Postback thru javascript

  • Thread starter Thread starter krallabandi
  • Start date Start date
K

krallabandi

I have asp button control on the page. I need to check some condition
before I postback the page.

Actually it is posting back for both true, false conditions.

I want to postback only if the condition is true. otherwise I want to
stay on the same page.

Note: I have many other asp buttons controls should postback. I need to
check for the condition only for one asp button control.

Thanks.
 
Handle the client-side onclick event. Make the javascript event handler to
return true if you want to proceed with the postback or false otherwise:

myButton.Attributes["onclick"] = "return myJavascriptHandler()";
 
the asp:button works in two ways.

1) standard html submit button. to cancel your client code returns false on
the onclick:

<input type=submit onclick='return postbackcheck();'>

2) the input is render with a onclick call to '__dopostback', usually
checking validation. here you need to duplicate the code to cancel.

the supported approach is to write a custom validator, and turn on causes
vaidation on your button.

-- bruce (sqlwork.com)
 
Back
Top