views:

78

answers:

2

ok.. i have a start page with textboxes i am sending the values entered in the textbox to another page using Cache on click of a next button.

Now i have a problem that when the user goes to the next page ad decides to go back again he should be able to do so and the values he entered in the textboxes should still be present.

is there a way to do so...

my code for sending values is:

Blockquote

protected void Button4_Click(object sender, EventArgs e)

    {

        if (TextBox2.Text == "" || TextBox3.Text == "")

        {

            Label1.Text = ("*Please ensure all fields are entered");

            Label1.Visible = true;

        }

        else

        {

            Cache["PolicyName"] = TextBox2.Text;

            Cache["PolicyDesc"] = TextBox3.Text;

           Response.Redirect("~/Addnewpolicy3.aspx");

        }

    }

and i receive this by on the next page as

protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            string pn = Cache["PolicyName"].ToString();

            string pd = Cache["PolicyDesc"].ToString();

            string os = Cache["OperatingSystem"].ToString();


        }
    }

Blockquote

+1  A: 

Cache is shared by all users. The code above will result in information being shared between users. If you want per-user temp storage you should use the Session instead. Other than that I can make 2 recommendations:

  1. Proceed with Session, your approach is fine
  2. Look at the Wizard control http://msdn.microsoft.com/en-us/magazine/cc163894.aspx

To make the values restore, in the controls simple do this:

<asp:TextBox ID="txtName" runat="server" text='<%=Session["Name"] %>'></asp:TextBox>
Nissan Fan
Worse, items in the Cache are thrown away to save memory at the discretion of the framework.
Joel Coehoorn
even if i use session how do i retain the values in the textbox if the user clicks on the back button...could u give me an example using session..Thanks
The memory issue is minor compared to sharing values between users.
Nissan Fan
Take a look above now for your sample.
Nissan Fan
thank you guys i have used session insted of cache as u suggested..Nissan Fan i tried ur code but if i put text='<%=Session["Name"] %>' it is showing <%=Session["Name"] %> in the textbox and not a value..I think there is some syntax missing..thanks
+1  A: 

It sounds like you want to take adavantage of Cross-Page postbacks which were added to ASP.NET in version 2.0

The following URL should offer some guidance

http://msdn.microsoft.com/en-us/library/ms178139.aspx

Matt Hidinger