c# - insert javascript only on page postback -


i'm sure straightforward i'm having trouble getting work. want add javascript function page, when page postsback.

so have button calls server-side code, , when finished , page re-loading want javascript function called.

thinking guess add hidden variable , set when button clicked, think i'd rather insert javascript onto page when loading back.

is possible, or way it?

thanks, neil

edit: okay onclick method in c# code.

protected void save(object sender, eventargs e) {     page.clientscript.registerclientscriptblock(this.gettype(), "alert", "<script type=\"text/javascript\">alert('hello world');</script>");      enforcementmatch(false);     enforcementmatch(true);     applicationnotmatch();     applicationmatch();     response.redirect(request.url.tostring()); } 

another edit: realised response.redirect @ bottom reloads page cancelling out code put in, duh!

you can use clientscriptmanager.registerclientscriptblock

http://msdn.microsoft.com/en-us/library/btf44dc9.aspx

if place on button click event, don't have worry if it's postback or not.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -