Avatar of mannevenu
mannevenu
 asked on

Alert messages in asp.net

I attched file. like this it is coming. i want  my project form as background in place of white screen.iam using update panel also. in cs iam writing this code for alert message

ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", "alert('Invalid file')", true);
             

             

alert1.PNG
ASP.NET

Avatar of undefined
Last Comment
prairiedog

8/22/2022 - Mon
Jens Fiederer

Try using RegisterStartupScript instead of RegisterClientScriptBlock (which might run before page is constructed)
mannevenu

ASKER
Ii tried this one.But this is not working
Jens Fiederer

What happened?  Same as in the picture?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
mannevenu

ASKER
yaa same in the picture
Jens Fiederer

The TIMING of your script is very important.

The way you had it originally, your alert was called at the top of the page, before anything else was rendered.

With the RegisterStartupScript, "The script block added by the RegisterStartupScript method executes when the page finishes loading but before the page's OnLoad event is raised."

Perhaps you draw a lot of your page in the OnLoad event?

Anyway, you'll want to arrange it so that the alert is called AFTER you set all the important background.  
If your OnLoad event emits the important stuff, you'll want to emit your script AFTER.
mannevenu

ASKER
Actually after clicking subit button it will come
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jens Fiederer

You mean the OK button on your alert window?
mannevenu

ASKER
Yes.Please give me solution for that one.With out refreshing that alert should come.Iam using update panel also.please help me it is urgent
Jens Fiederer

This is what you would expect when you run the javascript too early - it pauses until you complete the alert by pressing OK, then it finishes rendering.

You do NOT want to run that Javascript until your page is completely rendered.

It might be best to emit it as a function definition and adding it as an onload as in here:

http://javascript.about.com/library/blonload.htm

Your help has saved me hundreds of hours of internet surfing.
fblack61
prairiedog

Create a JavaScript, say called "displayAlert()" like this:

function displayAlert()
{
   alert("invalid file");
   return true;
}
then change your code to this:
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", "displayAlert()", true);
The "return ture" in the JavaScript should let your page display after the alert pops up.
Let me know if it works for you.
 
Jens Fiederer

He says it already DOES display after the alert pops up.

He wants it to finish displaying BEFORE the alert pops up, which means he has to complete everything that needs to be done before triggering that alert.  

Using
                    ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "alert", "displayAlert()", true);
triggers the alert BEFORE the page is rendered.


One needs to know everything that is involved in rendering the page (he has indicated at least a part of this is done using AJAX, which could happen AFTER the page is already completely sent over).  

The alert message is a nice way to see where you ARE, but in the end it needs to be triggered AFTER the last significant display operation has occurred.  

Without full access to your code it is not possible to say exactly where that is - if you are displaying pretty much a blank page, and later filling in with AJAX, you have to time the alert carefully.
ASKER CERTIFIED SOLUTION
prairiedog

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.