Display message (pop-up ?) before leaving a page

Greetings all

I have a page that requires certain conditions to be met (eg. various tables that need certain data in them).

What am I trying to do is on PageLoad, check for the necessary dependancies and if not existing, popup/display a message before redirecting to the appropriate page. In the attached snippet, the redirect works, but the message is not displayed ( which according to what I've read it shouldn't be).

What should I be doing?
sqlCommCheck.ExecuteNonQuery();
sqlConnect.Close();
if ((int)sqlCommCheck.Parameters[0].Value > 1)
   {
    Response.Write("There are no Grade records. Please contact your Administrator.");
    Response.Redirect("~/Default.aspx");
   }

Open in new window

allanmarkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DhaestCommented:
Probably it shows on the screen, but because you perform a redirect immediatly, you won't see it !

You can use this:
sqlCommCheck.ExecuteNonQuery();
sqlConnect.Close();
if ((int)sqlCommCheck.Parameters[0].Value > 1)
   {
    ASPNET_MsgBox("There are no Grade records. Please contact your Administrator.");
    Response.Redirect("~/Default.aspx");
   }

public void ASPNET_MsgBox(string Message) 
{ 
    
    System.Web.HttpContext.Current.Response.Write("<SCRIPT LANGUAGE=\"JavaScript\">" + Constants.vbCrLf); 
    
    System.Web.HttpContext.Current.Response.Write("alert(\"" + Message + "\")" + Constants.vbCrLf); 
    
    System.Web.HttpContext.Current.Response.Write("</SCRIPT>"); 
    
} 

Open in new window

0
Pratima PharandeCommented:
if ((int)sqlCommCheck.Parameters[0].Value > 1)
   {
 
Page.RegisterStartupScript(@"startup", @"<script> alert('There are no Grade records. Please contact your Administrator');location.href='Default.aspx'</script>");
   }
0
monarch_ilhanCommented:
Totally agree with Dhaest :)
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

Pratima PharandeCommented:
Page.RegisterStartupScript(@"startup", @"<script> alert('There are no Grade records. Please contact your Administrator');location.href='Default2.aspx'</script>");
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
allanmarkAuthor Commented:
Thanks!

Both methods work perfectly  -  if the Redirect is commented out.

Is there anything I can do about this?
0
Pratima PharandeCommented:
this script conatin the redirection code location.href='Default2.aspx'



Page.RegisterStartupScript(@"startup", @"<script> alert('There are no Grade records. Please contact your Administrator');location.href='Default2.aspx'</script>");
0
allanmarkAuthor Commented:
My mistake!! - typing ooops!!

Directory structure is as follows:    D:\Projects\School_Keeper_ASP\Admin\        -->    Here are my pages

Location of Default page is:  D:\Projects\School_Keeper_ASP\

So when the Script calls the Default2 page it can't be found. I've tried various combinations for the href
but can't get it to work.

How should I specify it?


 
0
Pratima PharandeCommented:
call your page name instade of default2 , just for example I used that
if your's is Default.aspx

Page.RegisterStartupScript(@"startup", @"<script> alert('There are no Grade records. Please contact your Administrator');location.href='Default.aspx'</script>");
0
allanmarkAuthor Commented:
Another IUE (Idiot User Error) - I left out a "/".
0
Pratima PharandeCommented:
??
0
allanmarkAuthor Commented:
Many, many thanks!!

Me = :)   :)    :)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.