1

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>
4

1 回答 1

0

我将onclick代码更改为:

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

ASP.net 生成的代码是:

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

它等于:

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

我的想法来自:我可以在 inline javascript if 语句中省略 else 吗?

于 2013-01-26T13:30:48.540 回答