只有在单击提交按钮
后才会触发必填字段验证器<asp:RequiredFieldValidator id="req" controltovalidate="txtphone" errormessage="please enter the details">
</asp:RequiredFieldValidator>
答案 0 :(得分:1)
如果您使用的是按钮字段,请尝试在验证器和按钮中应用Validation Group
属性,如下所示
<asp:RequiredFieldValidator id="req" runate="Server" controltovalidate="txtphone" errormessage="please enter the details" ValidationGroup="g">
<asp:button id="btn" runat="server" validationgroup="g">
答案 1 :(得分:1)
你的代码上缺少runat服务器
检查一下:
<form id="form1" runat="server">
Phone Number:<br />
<asp:TextBox runat="server" id="txtphone" />
<asp:RequiredFieldValidator runat="server" id="req" controltovalidate="txtphone" errormessage="Please enter your phone number!" />
<br /><br />
<asp:Button runat="server" id="btnSubmitForm" text="Ok" />
</form>
此致