动态创建的RequiredFieldValidator绕过客户端验证

编程入门 行业动态 更新时间:2024-10-22 16:38:56
本文介绍了动态创建的RequiredFieldValidator绕过客户端验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想一个必填字段校验器在运行时添加到我的网页。没什么特别的有:

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>

和@ codebehind

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。

推荐答案

您好所有尝试随着RequiredField验证这一个单选按钮

Hello All Try This one For Radio Buttons Along With RequiredField Validator

code

TableRow trow4 = new TableRow(); trow4.Style.Add("width", "100px"); TableCell tcel4 = new TableCell(); Label lb4 = new Label(); lb4.Text = Resources.QcLabelName.Gender; tcel4.Controls.Add(lb4); CSSCell(tcel4); table.Rows.Add(trow4); RadioButtonList rblist = new RadioButtonList(); rblist.ID = "rbtnmalendfemale"; rblist.Items.Add("Male"); rblist.Items.Add("Female"); tcel4.Controls.Add(rblist); trow4.Cells.Add(tcel4); table.Rows.Add(trow4); rblist.Visible = true; RequiredFieldValidator rFV5 = new RequiredFieldValidator(); TableCell tcl46 = new TableCell(); rFV5.ControlToValidate = "rbtnmalendfemale"; rFV5.ErrorMessage = "Gendor Selection Is Mandatory"; rFV5.Style.Add("color", "Red"); rFV5.ID = "Reqfield9"; tcl46.Controls.Add(rFV5); trow4.Cells.Add(tcl46); table.Rows.Add(trow4); rFV5.Visible = true;******

更多推荐

动态创建的RequiredFieldValidator绕过客户端验证

本文发布于:2023-11-16 04:34:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1601031.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:客户端   动态   RequiredFieldValidator

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!