I've spent half-the-morning working on this and I still can't find an answer anywhere. Please note this is a simplified example, the real project has tabs and customised sidemenus as well.
I have 2 webpages - test.aspx (with a textbox and 'Next' button) and target.aspx (with a 'Back' button).
TEST.ASPX -
TEST.ASPX.CS -Code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:Button ID="Button1" runat="server" Text="Next" OnClick="Navigate_Next" /> </div> </form> </body> </html>
Code:using System; public partial class test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { TextBox1.Text = Session["surname"].ToString(); } protected void Navigate_Next(object sender, EventArgs e) { Session["surname"] = TextBox1.Text; Server.Transfer("target.aspx"); } }
TARGET.ASPX -
Code:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="target.aspx.cs" Inherits="target" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <h1>Target Page</h1> <br /> <asp:Button ID="Button1" runat="server" Text="Back" OnClick="Navigate_Next" /> </div> </form> </body> </html>
TARGET.ASPX.CS -
When the user navigates from test.aspx to target.aspx and back, I want them to still see the value they typed into the test.aspx textbox. I've tried using Session variables to resolve this issue, but that isn't working because the test.aspx's Page_Load event is invoked before the Navigate_Next event. So the textbox value is getting deleted before it can be saved.Code:using System; public partial class target : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Navigate_Next(object sender, EventArgs e) { //Master.Authnavclass = "selectedTab"; Server.Transfer("test.aspx"); } }
My question is - does anyone know a way to preserve a form's values when they're navigating back and forth between separate webpages?




Reply With Quote