Wednesday, October 1, 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 7, 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 8, 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.

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

Tuesday, June 21, 2011 8:32 AM by b_balasubrahmanyam

i am using reportviewer control vs2008, i am trying print using

document.getElementById( 'rptviewer1).ClientController.LoadPrintControl(); this is returing false.

here LoadprintControl is searching "printframerptviewer1" since id is rptviewer1.

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

Tuesday, June 21, 2011 8:36 AM by b_balasubrahmanyam

help me for my previous comment.

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

Monday, October 1, 2012 10:41 AM by Carl

Great Script just what I needed :)

Thank you