Postback thru javascript

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.
 
E

Eliyahu Goldin

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()";
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top