Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear experts how can i call vbscript or javascript after page postback

I want to export my "div" to excel format on server side button click but my vbscript executes before filling "div". I want to execute it after page postback.
Posted

1 solution

Please add the following code to the event or function that causes the postback.

ScriptManager.RegisterStartupScript(Me.Page, Me.GetType, "CallScriptAfterPostback", "<script language='javascript'>MyJavascriptFunctionHere();</script>", False)


Added: you can retain everything except for MyJavascriptFunctionHere(); because that represent the javascript function that you want to call after postback. so let say:

protected void MyButton_Click(object sender, EventArgs e)
{
   //other codes here....
   ScriptManager.RegisterStartupScript(this.Page, this.GetType, "CallScriptAfterPostback", "<script language='javascript'>MyJavascriptFunctionHere();</script>", False)
}


>> please use this: language='javascript' instead of language="'javascript'". I don't know why single quote has a prefix of "'
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900