You say that you installed PostBackUrl on your second page. If you are going to do this, you need to use Page.PreviousPage to access your text field. But this is the easiest way:
First, leave only PostBackUrl. Setting PostBackUrl on the second page means that you say SECOND PAGE to handle the button, not the first page. Therefore, your session variable will never be set and will be zero when you try to pull it out.
This should work for ya.
And yes, you can also do this with QueryString, but if this is what you do not want the user to see / edit, then it is better to use the Session variable.
protected void submit_Click(object sender, EventArgs e) { string name = txtFirstName.Text.Trim(); Session["name"] = name; Response.Redirect("PageTwo.aspx"); }
Then on the second page (you don't need ToString ()):
protected void Page_Load(object sender, EventArgs e) { if (Session["name"] != null) { lblName.Text = Session["name"].ToString(); } }
EDIT . Make sure the button is pressed. Someone may fix me wrong, since most of my work I do is in VB.NET, and not in C #. But if you do not specify an OnClick value, your function will not be called.
<asp:Button ID="Button1" runat="server" Text="Click Me!" OnClick="submit_Click" />
source share