我需要验证文本框(数量),其中数据(数量)从数据库存储在后面的代码,我必须验证给定的输入值与变量值从后面的代码,以便用户不能使用更多的数量,然后在数据库中的值。
假设您在后面的代码中有一个Quantity
变量,它保存用户可以插入的最大数量,您需要向TextBox添加一个验证器,如下所示:
<asp:RangeValidator id="Range1"
ControlToValidate="TextBox1"
MinimumValue="0"
MaximumValue="<%# Quantity %>"
Type="Integer"
Text="Value inserted is more than the allowed maxium quantity"
runat="server"/>
将该变量设为公共变量或者创建一个属性来保存该变量的值然后你可以在aspx页面中访问它,像这样
<body>
<form id="form1" runat="server">
<div>
<h1><%=Name%></h1>
</div>
</form>
</body>
代码后面的代码应该是这样的
public string Name{ get; set; }
protected void Page_Load(object sender, EventArgs e)
{
Name = "Mega Mind";
}
正如我从你的问题标题中所理解的,而不是描述,你想在你的代码后面访问一个变量,从你的客户端脚本代码(即aspx)
你可以使用ClientScriptManager.RegisterClientScriptBlock()来注册变量
更多信息在这里输入链接描述