Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

input button causes RequiredFieldValidator to fire

I have an input button on my page that is dynamically created, every time I press it, it fires the RequiredFieldValidator for the blank field in the email address. is there a way to ovverride it?

input code:

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

validator 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" />
like image 363
Moran Monovich Avatar asked Sep 07 '26 08:09

Moran Monovich


1 Answers

I have an input button on my page that is dynamically created, every time I press it, it fires the RequiredFieldValidator for the blank field in the email address. is there a way to ovverride it?

HtmlButton.CausesValidation Property

Mark UP

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


yes, i want it to do a postback

HtmlButton.OnServerClick Method

Code Behind

protected void FancyBtn_Click(object sender, EventArgs e)
{  

}

Mark Up

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

like image 181
Pankaj Avatar answered Sep 10 '26 07:09

Pankaj