Call Javascript Function on Postback

I ran into this problem when I had to call a javascript on page load after my server-side code threw an exception to the user.

If you want to call a javascript function on page postback, you'll need to add an EventListner to the current document.

 

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

function doSomething(){.... }


if (window.addEventListener)
    window.addEventListener("load", doSomething, false);
else if (window.attachEvent)
    window.attachEvent("onload", doSomething);
else if (document.getElementById)
    window.onload= doSomething;

</script>

Published Tuesday, February 05, 2008 4:55 PM by Kiyoshi
Filed under:

Comments

# rascunho &raquo; Blog Archive &raquo; links for 2008-02-06

Wednesday, February 06, 2008 3:31 PM by rascunho » Blog Archive » links for 2008-02-06

Pingback from  rascunho  &raquo; Blog Archive   &raquo; links for 2008-02-06

# re: Call Javascript Function on Postback

Friday, August 08, 2008 9:23 AM by Yogi

this blog was helpful to me

# re: Call Javascript Function on Postback

Saturday, October 04, 2008 12:49 AM by Chaitanya

Hey thats great... it worked. I am using frames and depending on the menu selected in to drop down I am changing the link to open page in left frame. For this I have to send query strings which was re initializing when page was auto postback. But above code solve my problem. Thanks a lot.

# re: Call Javascript Function on Postback

Sunday, December 06, 2009 10:56 PM by valar

Thanks for the piece of code. Helped me a lotttttttttt....

# re: Call Javascript Function on Postback

Wednesday, March 17, 2010 8:50 AM by Raju

Thanks for sharing your thought.. Really it is very helpful.

# re: Call Javascript Function on Postback

Sunday, May 16, 2010 3:01 PM by Andrew

Having trouble firing this when postback occurs.  I only want a function to fire when it is a fresh page load not on the autopostback of a control.

# Call Javascript Function on Postback &#8211; Kiyoshi&#8217;s Blog | Write A Blog

Pingback from  Call Javascript Function on Postback &#8211; Kiyoshi&#8217;s Blog | Write A Blog

# re: Call Javascript Function on Postback

Friday, March 04, 2011 8:36 AM by vikram

thanks a lot... this helped me... this is exactly what i wanted... :-)

# re: Call Javascript Function on Postback

Wednesday, June 05, 2013 2:58 PM by xelaDGlITruL

RXeWGE Wow, great article.Really looking forward to read more. Cool.

Leave a Comment

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