3

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" />
Moran Monovich
  • 595
  • 1
  • 14
  • 27

3 Answers3

1

Make it server side button by writing runat="Server" attribute and make a CausesValidation="true|false" on your requirements. If you do false it will not validate. Do let me know if it solves the problem

Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
1

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>

Pankaj
  • 9,749
  • 32
  • 139
  • 283
0

try to add runat="server" to input button as shown:

*Note* the runat="server". While asp:button probably renders similarly, if what you really want it an HTML button input, you can use that. Yes, ASP.NET will pick up the value on the server side.**

<input type="button" runat="server" id="btnTest" value="change" onclick="doPostBack('btnTest', '');"/> 
coder
  • 13,002
  • 31
  • 112
  • 214
  • I think you may try this http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx – coder Apr 17 '12 at 09:28