|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
making sure page loadshey 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 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 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 > > >
wildcard mapping
Delayed Code Execution? Authentification - Server Variables ( omg! ) Pulling from Access Query, Cannot Change Date/Time Formats I/O stream performance Security exception with impersonate true for a webservice Help debugging...where do I look? Overture/Yahoo & Google PPC referral tracking Is it possible to have more than one login control in a website? Changing Location of Solution File in VS2005 |
|||||||||||||||||||||||