Please clarify your question. I think your asking why the whole page goes white when the box is shown? If so, the answer is because you are making the alert pop-up as the page is loading, or rather before any of the rest of the page has been loaded. Think of the browser as working through each line of HTML you pass it line-by-line and doing whatever is necessary for that line then moving on. Your
alert
statement therefore comes as one of the first lines of HTML, so the box is shown first. The browser then has to wait until the user clicks okay before it can continue to process the because that is the function of the alert box. So while the box is shown it has to display a blank (white) page to the user as it does not know what else to show (since it hasn't processed the rest of your page).
The solution is to either: Use jQuery and it's
$(document).ready
method to make your alert box appear only when the rest of the page has been processed and rendered or to use the C# Literal control to add your script block at the end of your output. E.g.
void Page_Load()
{
Literal ScriptSection = new Literal();
ScriptSection.Text = "<script lang=\"text/javascript\">alert('Hello world!');</script>";
Page.Form.Controls.Add(ScriptSection);
}
The Literal control outputs exactly whatever text you set it to - it bypasses ASP.Net processing basically meaning you can write HTML in your code. Be warned though, this makes code messy if used too much!
Hope this helps,
Ed
Edit: Useful links:
jQuery.ready :
http://api.jquery.com/ready/[
^]
MSDN Literal control :
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.aspx[
^]