473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

making sure page loads

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
Sep 5 '06 #1
2 1169
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.GetTyp e(), "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" <ro*****@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.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

Sep 5 '06 #2
thank you for the help.

"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.GetTyp e(), "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" <ro*****@discussions.microsoft.comwrote in message
news:61**********************************@microsof t.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


Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CST | last post by:
Hi All, I have a "Digital Dashboard" that basically has 4 IFrame sections. The page flows in the following order: Messages, Stocks, Weather, User Links. Please note that this order needs to...
1
by: middletree | last post by:
For an ASp Intranet app, I have some code that should work, but I am not able to make it happen for some reason, after spending considerable time on this. I am pretty thick when it comes to...
7
by: Sens Fan Happy In OH | last post by:
I'm having majour issues with FrontPage 2K and a webpage that I am having to create from scratch based on someone else's prior work. I hope someone can look at the source code for the page in...
1
by: mark | last post by:
Hi I am trying to count the number of times a page loads. When I hit the submit button I can get the page to count once using ispostback to check . I am trying to incriment a variable everytime...
351
by: CBFalconer | last post by:
We often find hidden, and totally unnecessary, assumptions being made in code. The following leans heavily on one particular example, which happens to be in C. However similar things can (and...
3
by: Alex | last post by:
Sorry if this is not a correct forum to post to. I have a page from my service provider that loads 1000's of table cells. These cells load for 3-4 mins and links on that page usually not...
8
by: yawnmoth | last post by:
A webpage can include any number of images, cascading stylesheets, frame's, etc. How might I go about making it so a particular image loads before any of these others? Ideally, the image would...
10
by: Antha | last post by:
Hi! I have a small e-commerce site but for everything else webrelated I'm practically virgin... I'd like to offer some sort of quiz in my shop so people can interactively find out which...
0
by: Andrus | last post by:
MSDN Winforms DataGridView VirtualMode with caching sample code DataRetriever loads two pages always to cache thus making 2 database accesses. If datagridview uses one page of data, second page...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.