Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to display a msg and then redirect to a page on click of okay button of the msg. .


C#
Response.Write("<script>alert('my message')</script>");
Response.Redirect("page.aspx");

this code redirects without showing message!!
Posted
Updated 16-Nov-11 23:15pm
v2

Hi Pramod

Try the following

Response.Write("<script>if(confirm(('my message'))){window.location=urlname;}</script>");


Hope this helps
 
Share this answer
 
Comments
Prince Antony G 17-Nov-11 6:07am    
my 5+
Try this

XML
ClientScriptManager CSM = Page.ClientScript;

            string strconfirm = "<script>if(window.confirm('Are you sure?')){window.location.href='Default2.aspx'}</script>";
            CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);
 
Share this answer
 
Comments
Prince Antony G 17-Nov-11 6:03am    
nice code..my 5+
demouser743 17-Nov-11 6:25am    
Thanks gpaantony :)
This code writes to output instructions for browser to show alert message user. But this output will never be sent to the client, because next line instructs your web application to send this client response with code 302 and address to which the user must be redirected instead.
You should use Javascript to perform redirect from the client. The code would look loke the following:
C#
Response.Write("<script>alert('my message'); ");
Response.Write("window.location='[new address]'</script>");
 
Share this answer
 
Comments
Pramod Harithsa 17-Nov-11 6:28am    
thanks for the explanation. .
In the linkbutton, you can used the onclientclick event is used to show the confirm message and onclick event used to redirect the page

XML
<asp:LinkButton  ID="btn_Cancel"  runat="server" Text="Cancel"  OnClientClick="return confirm('Are you sure want to cancel this Request?')"   />


You can rewrite the confirm text as alert message.
 
Share this answer
 
v2
try in the following way this must work :
XML
ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "<script
language='JavaScript'>alert(ABCDEFGH');</script>");

Response.Redirect("Default.aspx");

and u to redirect in javascript also :
HTML
alert ('ABCDEFGH'); window.location.href = 'newpage.aspx';
 
Share this answer
 
HTML
<code>ClientScriptManager CSM = Page.ClientScript;
 
            string strconfirm = "<script>if(window.confirm('Are you sure?')){window.location.href='Default2.aspx'}</script>";
            CSM.RegisterClientScriptBlock(this.GetType(), "Confirm", strconfirm, false);</code>
 
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