Click here to Skip to main content
15,909,051 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

In my application I am saving the data after that I am redirecting the page to the same page. Here I need to display the message as data saved successfully after redirecting to the page. Can any one help me to solve this problem.

Thanks in Advance
Posted

You can use the javascript alert in the page load of the page you are redirecting to using response.write .
 
Share this answer
 
Why you are re-directing to same page, though you are saving the data in the same page..?? I think No need of redirecting to same page.

by the way, you can display the message either of the two ways.

Method I: using message box.

C#
string strJscript = "<script language='javascript'> alert('Details are saved successfully');</script>";

Page.CLientScript.RegisterClientScriptBlock(this,this.GetType(),"Myscript",strJscript,false);


method II:
keep one Label and display message as Label Text.

C#
Label1.Text="Details are saved sucessfully";


hope this helps..
 
Share this answer
 
v2
protected void Page_Load(object sender, EventArgs e)
{
    // First time logic
    if (!IsPostBack)
    {
        Response.Write("U r success message");
    }
}
 
Share this answer
 
Try this,

Pass querystring while redirecting..

C#
Response.Redirect("Default.aspx?mess=true");


In Default.aspx.cs page load

Then check it in page load event of that page.

C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["mess"] != null)
        {
            Response.Write("<script>alert('Message savedsuccessfully');</script>");
        }
    }
 
Share this answer
 
v2
use scriptmanager to call javascript

C#
ScriptManager.RegisterStartupScript(this, this.GetType(), "*&^%", "alert('Invoice has been submitted successfully');", true);



if you have any queries then tell me.
 
Share this answer
 
v2
To make your web application efficient you can add one class named MessageBox in your AppCode folder.
please cheak this link
www.codeproject.com/KB/webforms/AspNetMsgBox.aspx[^]
 
Share this answer
 
v4
Comments
Wendelius 20-Dec-11 16:59pm    
Link formatted
Hello,

When you save details and redirect to same page then you just write code like this,

C#
if (SaveDetails())
        {
            Session["sucmsg"] = "msg";
            Response.Redirect("~/MypagePath.aspx");
        }


You can use javascript at loadtime here with session. The secure way here is use session whenever you redirect to page. After at load time you just put code like this,

C#
if (!IsPostBack)
{
    if (Session["sucmsg"] != null)
    {
         ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('Invoice has been submitted successfully');", true);
         Session.Remove("sucmsg");
     }
}


In this way you can show msg and also remove session. You can also pass any secure message to session. But make sure to remove session variable.

I will be back if any query.
 
Share this answer
 

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