1
votes

For some reason I'm using HTML controls with runat="server". One of these controls is a button. I have client-side validation function. I wan't to fire server-side action after successful client-side validation.

HTML:

<button type="button" id="webSubmit" 
runat="server" 
onclick="return $('#form1').valid();">Submit</button>

Server side:

protected void webSubmit_ServerClick(object sender, EventArgs e)
{
   //foo
}

When I click the button it validates the form but does not postback even if validation returns true.

It's generated by ASP.net:

<button onclick="return $('#form1').valid(); __doPostBack('webSubmit','')" 
id="webSubmit" type="button">Submit</button>
1
What do you have the Button.UseSubmitBehavior Property set as is it True..? Button.UseSubmitMethodMan

1 Answers

0
votes

I changed onclick code to this:

onclick="$('#form1').valid() && "

ASP.net generated code is:

<button onclick="$('#form1').valid() &&  __doPostBack('webSubmit','')" 
id="webSubmit" type="button">Submit</button>

It's equal to:

if ($('#form1').valid()){
__doPostBack('webSubmit','')
}

I got the idea from: Can I omit the else in an inline javascript if statement?