Reputation: 79
when I add javascript confirm to my button, requiredfieldvalidators stops working
<form id="form1" runat="server">
<asp:Button runat="server" Text="save" OnClick="add_Click" ID="add" OnClientClick="return confirm('ok?');" />
<asp:TextBox ID="txt1" runat="server" ></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="txt1" ID="rfv1" runat="server"
Display="Static" ErrorMessage="Required!"></asp:RequiredFieldValidator>
</form>
Upvotes: 2
Views: 180
Reputation: 592
I don't have exact answer for you. But there is one solution by using html5 feature.
Just put required inside your textbox field and remove the required field validator.
html5 will take care for validation message too.
It works for me and I'm using HTML5 textbox validations in my project.
<asp:TextBox ID="txt1" runat="server" required="true">
Upvotes: 1
Reputation: 351
add validation group on the button and RequiredFieldValidator and it will work
Upvotes: 1
Reputation: 105
Just add this code to your web.config file and it will work fine
<appSettings> <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /> </appSettings>
Upvotes: 2