正如标题所说。可能有什么不妥?
我的网页上有一个常规的TextBox - <asp:TextBox ID="tb" runat="server" />
以下作品:
<asp:RequiredFieldValidator ID="r" runat="server" ControlToValidate="tb" ErrorMessage="error" />
以下不起作用:
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv";
rfv.ControlToValidate = tb.ID;
rfv.ErrorMessage = "error";
答案 0 :(得分:3)
您需要添加必填字段验证器
RequiredFieldValidator rfv = new RequiredFieldValidator();
rfv.ID = "rfv";
rfv.ControlToValidate = tb.ID;
rfv.ErrorMessage = "error";
yourFormId.Controls.Add(rfv);// you need to add this