Loading ...

how to get previous page and details remain

Who is online?  0 guests and 0 members
home  »  forums   »  asp.net topics   »  web forms / data controls   » how to get previous page and details remain

how to get previous page and details remain

Posts under the topic: how to get previous page and details remain

Posted: 7/31/2011

Lurker 10  points  Lurker
  • Joined on: 7/8/2011
  • Posts: 2

Hey!

I know it is a common question but I am too close and cant find solution. I have two Pages between A.aspx and B.aspx

When you fill your name and surname on the textbox controls and then click on send button, redicted to B Page to say thank you for ordering but if you want to fill the form again for another ordering, click on back button from B Page to go back to previous page (A Page) and details (your name and surname) should remain on textbox controls. So you dont need to write your name and surname again. How to do this?

markup:

A.aspx:

<label>Name:</label> <asp:TextBox ID="txtName" runat="server"></asp:TextBox>

<label>Surname:</label> <asp:TextBox ID="txtSurname" runat="server"></asp:TextBox>

 <asp:Button ID="Send" runat="server" Text="Send Email" onclick="Send_Click" />

A.aspx.cs (C#):

  protected void Send_Click(object sender, EventArgs e)

{

Response.Redirect("B.aspx");

}

B.aspx:

<p>Thank you for ordering. We will contact you very soon.</p>

<p>Do you want to order item again? Go back to A Page  <asp:Button ID="btnBack" runat="server" Text="BACK" onclick="Send_Click" />
</div>

B.aspx.cs (C#):

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.UrlReferrer.ToString());

    }

Problem: when i clicked on back button, redicted to A Page and all the details (name and surname) are gone from textbox control. I want these details to remain, dont need to write it again.

Your help will be highly appreciated. Thanks for your time :-)


Posted: 7/31/2011

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490

In this stateless protocol architecture you have following options go with QueryString or Session or some cache. I am showing the way of doing that with Session. At the end of your steps you can clear the Session variables.

A.aspx 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
       if(!Page.IsPostBack)
       {
           //Set values from Session if exists
           if (Session["Name"]!=null)
           {
               txtName.Text = Session["Name"].ToString();
           }
           if (Session["Surname"] != null)
           {
               txtSurname.Text = Session["Surname"].ToString();
           }
       }

    }

    protected void Send_Click(object sender, EventArgs e)
    {
        //Save values in session before moving to second page
        Session["Name"] = txtName.Text;
        Session["Surname"] = txtSurname.Text;

        Response.Redirect("B.aspx");

    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Title</title>
</head>
<body>
    <form id="HtmlForm" runat="server">
    <label>
        Name:</label>
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <label>
        Surname:</label>
    <asp:TextBox ID="txtSurname" runat="server"></asp:TextBox>
    <asp:Button ID="Send" runat="server" Text="Send Email" OnClick="Send_Click" />
    </form>
</body>
</html>


B.aspx 

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write(Request.UrlReferrer.ToString());
 
    }

    private void Send_Click(object sender, EventArgs e)
    {
        Response.Redirect("A.aspx");
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Title</title>
</head>
<body>
    <form id="HtmlForm" runat="server">
    <p>
        Thank you for ordering. We will contact you very soon.</p>
    <p>
        Do you want to order item again? Go back to A Page
        <asp:Button ID="btnBack" runat="server" Text="BACK" OnClick="Send_Click" />
    </form>
</body>
</html>

 


Page 1 of 1 (2 items)