Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good day All,
I've been trying to get a dialog box to be displayed using JavaScript.
However, the highlighted piece of code (as shown in the code below) does not do anything 'VISIBLE' that I can see.

C#
}
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "alertmessage", "javascript:alert('You cannot access this page yet. Please Log in or Register')", true);
            Response.BufferOutput = true;
            Response.Redirect("Account/Login.aspx", true);
        }
    }


I needed a dialog box to be presented to the user before the redirection to another webpage. However, the user is redirected to the webpage without the dialog box popping up.

Please how do I resolve this or is there a simple (beginner's level) resource or site that could push me in the right direction?

Thanks for taking the time to read this. Looking forward to your replies.
Posted

The reason you don't see the popup is because you redirected to another page.

So, there are a couple of workarounds I can think of.

1. Redirect to the other page and add a flag in the query string that the new page checks for and then displays the messagebox.
2. Display the messagebox and then redirect to the other page in JavaScript, not in C#.
 
Share this answer
 
Comments
Arthur Ezenwanne 4-Dec-14 11:04am    
Thanks RyanDev for your response, could you instruct me on how to implement you second workaround?
ZurdoDev 4-Dec-14 11:06am    
Just google it. In JS you can do window.location ="newurl.aspx" to send to a new page.
C#
else
{
    Response.Write("alert('You cannot access this page yet. Please Log in or Register');");
    Response.BufferOutput = true;
    Response.Redirect("Account/Login.aspx", true);
}


Try this, if it works :)

-KR
 
Share this answer
 
Comments
Arthur Ezenwanne 4-Dec-14 11:02am    
Thanks KR but that fix did not work. Still behaved the same way.
ZurdoDev 4-Dec-14 11:06am    
That won't work because all of that happens on the server side and so the Response.Write gets lost when you do a Redirect.

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