Home All Groups Group Topic Archive Search About
Author
5 Sep 2006 8:25 PM
rodchar
hey all,
i have a button on my web form that after it posts back it suppose to throw
up an alert. it works fine but that it throws the alert before the entire
page has been displayed. is there any way i can get it to display the alert
after the entire page is displayed?

thanks,
rodchar

Author
5 Sep 2006 10:54 PM
Rob
rodchar,

To do this you need to display the alert from the BODY tag's onload method.

OnLoad can be a bit of a pain to handle correctly, especially if you have 2
or more bits of code that need OnLoad handlers, not to mention cross browser
support.

Here's a chunk of code I like for onload (handles multiple onload handlers
and is cross browser compatabile):

//
// Add the addLoadEvent function
//  - A clean cross browser method to add a window.onload method
//
ClientScript.RegisterClientScriptBlock(this.GetType(), "addLoadEvent",
"function addLoadEvent(func) { var oldonload = window.onload; if (typeof
window.onload != 'function') { window.onload = func; } else { window.onload
= function() { if (oldonload) { oldonload(); } func(); } } }", true);

More or less the above checks if there is an existing OnLoad handler. If
there isn't then the function passed as the argument is used. If there is an
existing onload handler then a new function is defined that calls the
existing onload handler and then calls the function passed as the argument.
This new function is then setup as the onload handler.

With that javascript function defined,you can then add as many onload
handlers as you need. To display an alert after the page has fully loaded:

string ShowMyAlert = "addLoadEvent(function() { alert('hello'); });";
ClientScript.RegisterStartupScript(this.GetType(), "ShowMyAlert",
ShowMyAlert, true);

Regards,

Rob


Show quoteHide quote
"rodchar" <rodc***@discussions.microsoft.com> wrote in message
news:61982682-AEA6-45B6-9617-A5FC48524A89@microsoft.com...
> hey all,
> i have a button on my web form that after it posts back it suppose to
> throw
> up an alert. it works fine but that it throws the alert before the entire
> page has been displayed. is there any way i can get it to display the
> alert
> after the entire page is displayed?
>
> thanks,
> rodchar
Are all your drivers up to date? click for free checkup

Author
6 Sep 2006 12:42 PM
rodchar
thank you for the help.

Show quoteHide quote
"Rob" wrote:

> rodchar,
>
> To do this you need to display the alert from the BODY tag's onload method.
>
> OnLoad can be a bit of a pain to handle correctly, especially if you have 2
> or more bits of code that need OnLoad handlers, not to mention cross browser
> support.
>
> Here's a chunk of code I like for onload (handles multiple onload handlers
> and is cross browser compatabile):
>
> //
> // Add the addLoadEvent function
> //  - A clean cross browser method to add a window.onload method
> //
> ClientScript.RegisterClientScriptBlock(this.GetType(), "addLoadEvent",
> "function addLoadEvent(func) { var oldonload = window.onload; if (typeof
> window.onload != 'function') { window.onload = func; } else { window.onload
> = function() { if (oldonload) { oldonload(); } func(); } } }", true);
>
> More or less the above checks if there is an existing OnLoad handler. If
> there isn't then the function passed as the argument is used. If there is an
> existing onload handler then a new function is defined that calls the
> existing onload handler and then calls the function passed as the argument.
> This new function is then setup as the onload handler.
>
> With that javascript function defined,you can then add as many onload
> handlers as you need. To display an alert after the page has fully loaded:
>
> string ShowMyAlert = "addLoadEvent(function() { alert('hello'); });";
> ClientScript.RegisterStartupScript(this.GetType(), "ShowMyAlert",
> ShowMyAlert, true);
>
> Regards,
>
> Rob
>
>
> "rodchar" <rodc***@discussions.microsoft.com> wrote in message
> news:61982682-AEA6-45B6-9617-A5FC48524A89@microsoft.com...
> > hey all,
> > i have a button on my web form that after it posts back it suppose to
> > throw
> > up an alert. it works fine but that it throws the alert before the entire
> > page has been displayed. is there any way i can get it to display the
> > alert
> > after the entire page is displayed?
> >
> > thanks,
> > rodchar
>
>
>

Bookmark and Share

Post Thread options