Wednesday, October 01, 2008 11:45 AM azamat_ali

To execute Javascript from the Button click and then run the server side code.

 An easy ways to do this is to call the __doPostBack() function of the javascript. An example is as follows:

 <input type="button" id="Button2" value="Button 2 Click" onclick="DoPostBack()" />


<script language="javascript" type="text/javascript">

function DoPostBack()
{
  //Any javascript statements....

__doPostBack('Button2','My Argument');
}

</script>
 

However in  Visual Studio 2005, the server and the client code can be directly run from the button attributes only.

OnClick property: For server side scripts

OnClientClick: For client side scripts

E.g. 

<asp:Button ID="btnClickMe" runat="server" Text="Click Me" OnClick ="btnClickMe_Click"  OnClientClick="DoPostBack();" />


 

Filed under: , , , , , , ,

Comments

# re: To execute Javascript from the Button click and then run the server side code.

Thursday, May 07, 2009 1:34 PM by srushaggs

I am trying this right now to call both server and client side functions, but I cannot control the order they are called.  I have a ReportViewer that needs to be refreshed in the code behind, and then have the clientside call ReportViewer ClientController.LoadPrintControl()

Any thoughts on how to solve this problem?

I am trying to Render a report and bring up the print dialogue with a single click and not have the user see the report at all.

# re: To execute Javascript from the Button click and then run the server side code.

Friday, May 08, 2009 4:42 PM by PataPata

dear srusaggs, the way I would do it is register a javascript with the code you need on the page in the codebehind that handles the server event.

Leave a Comment

(required) 
(required) 
(optional)
(required)