Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
how to display a message before redirect.
response.redirect("default.aspx") is not working...
Posted
Updated 30-Dec-19 0:30am
v2

Try
Response.Write("<script language='javascript'>window.alert('Your Message');window.location='yourpage.aspx';</script>");

It will display pop up window message, then after redirect to another web page.
 
Share this answer
 
Comments
Uday P.Singh 23-Jul-11 8:00am    
my 5! see my answer
Neeraj Kumar Prajapati 5-Sep-13 5:30am    
thanks it is helpful. But it needs some changes or it will show error. Just remove double inverted commas from javascript i.e. it must be 'javascript' only, not "'javascript'".

Response.Write("<script language='javascript'>window.alert('Your Message');window.location='yourpage.aspx';</script>");
Ankur Mahor 23-May-17 4:00am    
Thanks dear. You have solved my problem.
you can also do it by creating the javascript function and calling it in your cs code like this:

JavaScript function:

C#
function ShowMessage()
{
      alert('your message');
      window.location.href='default.aspx';
}


CSharp code:

ScriptManager.RegisterStartupScript(this, this.GetType(), "key", "ShowMessage()", true);


hope it helps :)
 
Share this answer
 
when you need to redirect your page you replace your Response.redirect is following code:-
XML
RegisterStartupScript("save", "&lt;script type=\"text/javascript\"&gt; alert('Save successfully');  window.location.href = "your url"; &lt;/script&gt;");

in above code is execute and display message and go to another page.
I hope solve your problem.
 
Share this answer
 
v3
Comments
RaviRanjanKr 23-Jul-11 6:56am    
Always keep normal sentences away from "pre" tags. its only for Codes :)
On the page you are working on, do the following:

1. Add a separate page to your application named popup.aspx.
2. Put an iframe with 0 width and height on your current page.
3. Set the src of your iframe to popup.aspx on the event you are working on.
4. Create a JavaScript function for alert message on your popup.aspx page and call it on page's onload.
5. After setting the src of your iframe in Step 3, you next put the location.href="/KB/answers/default.aspx".
 
Share this answer
 
v2

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