Initiate PostBack From Client-side Script

  • Thread starter Thread starter Jordan
  • Start date Start date
J

Jordan

I'm trying to initiate Postback from client-side script, and here's what I
have that doesn't work: I have an <asp:Button> on the same page named
btnSave that the user can click (its functionality works fine). I want to
call the button's server-side functionality from the client-side script (in
response to things happening in the client other than the user clicking on
the save button).

function DoSomethingInClient()
{
Do Some Stuff Here
__doPostBack('btnSaveClick','');
}

What could be wrong with this?

Thanks.
 
Are you sure you have the method __doPostBack() in your client? If you
don't have any controls set for postback, it can happen that the code is not
generated to the client.

In the Framework documentation or MSDN, search for the article titled
"Generating Client-Side Script for Postback."

It talks about the GetPostBackEventReference method. This method will
return method call string so you can use it in programatically generated
client scripts but the most important thing it will do for you is that, if
it doesn't already exist by other means, it will generate the __doPostBack
method itself so that you can call it.

Dale Preston
MCAD, MCSE, MCDBA
 
Back
Top