Enter button triggers RequiredFieldValidator

I have an enter button on my page that is dynamically created, every time I click it, it launches the RequiredFieldValidator for an empty field in the email address. is there any way to override it?

input code:

<input class=\"hledat\" id=\"searchbutton\" type=\"image\" src=\"search-button.gif\" value=\"{0}\" onclick=\"search('{1}');\" onkeypress=\"search('{1}');\"/>"

Security Code:

<asp:TextBox runat="server" ID="txtEmail" ClientIDMode="Static" Width="98%" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="txtEmail" ErrorMessage="email"
    Display="dynamic" ValidationGroup="newsletter" />
<asp:RegularExpressionValidator runat="server" ControlToValidate="txtEmail" ErrorMessage="email"
    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="dynamic"
    ValidationGroup="newsletter" />
+3
source share
3 answers

I have an enter button on my page that is dynamically created, each I click on it, it launches the RequiredFieldValidator to blank the field in the email address. is there any way to override it?

HtmlButton.CausesValidation Property

Mark UP

<button causesvalidation="false" /><button ID="StateQueryButton" CausesValidation="False" runat="server"> Submit </button>


yes i want to do postback

HtmlButton.OnServerClick method

Code for

protected void FancyBtn_Click(object sender, EventArgs e)
{  

}

Mark

<button causesvalidation="false" /><button ID="StateQueryButton" CausesValidation="False" OnServerClick=" FancyBtn_Click" runat="server" > Submit </button>

+1
source

, runat = "" CausesValidation = "true | false" . false, . , .

+1

try adding runat = "server" to enter the button as shown:

* Note * runat = "server". While the asp: button button probably works the same way, if you really want it to be entered as an HTML button, you can use it. Yes, ASP.NET will get the server-side value. **

<input type="button" runat="server" id="btnTest" value="change" onclick="doPostBack('btnTest', '');"/> 
0
source

All Articles