动态创建的requiredfieldvalidator绕过客户端验证
我正在尝试在运行时向我的页面添加必填字段验证器。 那里没什么奇特的:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:ValidationSummary ID="ValidationSummary1"
runat="server" ShowMessageBox="True" ShowSummary="False" />
</form>
和@ codebehind
protected void Page_Init(object sender, EventArgs e)
{
RequiredFieldValidator theValid = new RequiredFieldValidator();
theValid.ID = "0000" + "RFV";
theValid.ControlToValidate = TextBox1.ID;
theValid.ErrorMessage = "Message here"
theValid.Text = "*";
theValid.Display = ValidatorDisplay.Dynamic;
theValid.EnableClientScript = true;
theValid.EnableViewState = true;
theValid.SetFocusOnError = true;
theValid.Enabled = true;
theValid.Visible = true;
Page.Validators.Add(theValid);
form1.Controls.Add(theValid);
}
当我单击按钮时,它只验证服务器端,而不验证客户端。我缺少什么?
TIA。
I am trying to add a required field validator to my page at runtime.
Nothing fancy there:
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:ValidationSummary ID="ValidationSummary1"
runat="server" ShowMessageBox="True" ShowSummary="False" />
</form>
and @ codebehind
protected void Page_Init(object sender, EventArgs e)
{
RequiredFieldValidator theValid = new RequiredFieldValidator();
theValid.ID = "0000" + "RFV";
theValid.ControlToValidate = TextBox1.ID;
theValid.ErrorMessage = "Message here"
theValid.Text = "*";
theValid.Display = ValidatorDisplay.Dynamic;
theValid.EnableClientScript = true;
theValid.EnableViewState = true;
theValid.SetFocusOnError = true;
theValid.Enabled = true;
theValid.Visible = true;
Page.Validators.Add(theValid);
form1.Controls.Add(theValid);
}
When I click the button it only validates server-side, but not client-side. What am I missing?
TIA.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 jquery 检查您的代码。
如果页面中存在验证器,它将在客户端的单击(提交)事件上进行验证。
You can to check your code with jquery.
If validator exists in page it will validate on click (submit) event client-side.
大家好,尝试一下单选按钮和必需字段验证器
代码
Hello All Try This one For Radio Buttons Along With RequiredField Validator
Code