Click here to Skip to main content
15,915,772 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
I need a small clarification.
When i use the below code for confirmation.
I am getting the confirmation box but that time only the confirmation box is visile.
Web page other details are becoming white can not see.
Could you please help

Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "script", "alert('New Customer created Successfully');", true);


Thanks
Posted

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.

C#
void Page_Load(/*whatever args go here*/)
{
   //Add in all your other output here (basically put all your other code here)
   
   //Now add in the alert box
   Literal ScriptSection = new Literal();
   ScriptSection.Text = "<script lang=\"text/javascript\">alert('Hello world!');</script>";
   Page.Form.Controls.Add(ScriptSection);
   //For the above line you could also use any control on your page e.g. MyControl.Controls.Add 
}


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[^]
 
Share this answer
 
v2
Comments
Lancy.net 19-Feb-12 6:38am    
Thanks Edward you are right my question is why the whole page goes white when the box is shown?
Ed Nutting 19-Feb-12 6:38am    
Which I then answered....
Hi, Arokia, i have posted your answer already, if it solves your problem then rate this.
 
Share this answer
 
Hi, use below code:

C#
ScriptManager.RegisterStartUpScript(this,this.getType(), "script", "alert('New Customer created Successfully');", true);
 
Share this answer
 
ScriptManager.RegisterStartupScript(Button1, Button1.GetType(), "script", "alert('New Customer created Successfully');", true);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900