0

I doing with sessions. On first page I have code

Response.Redirect("welcome.aspx");
Session["me"] = TextBox1.Text;

and on welcome page I am writing this code on form load event

if(Session["me"] != null)
{
  Label1.Text = (string)Session["me"];
}
else
{
  Label1.Text = "session not created";
}

it gives me "Session not created" else part is running always. Is something wrong with my code. please help me.

0

4 Answers 4

2

You have to create the session before redirect to the page so your code must be like this:

Session["me"] = TextBox1.Text;
    Response.Redirect("welcome.aspx");
Sign up to request clarification or add additional context in comments.

Comments

1

Set session before redirecting to other page

Session["me"] = TextBox1.Text;
Response.Redirect("welcome.aspx");

Comments

1

You have to first set the session and then redirect to other page. so it should be like this:

Session["me"] = TextBox1.Text; // set the session
Response.Redirect("welcome.aspx"); // redirect to other page

Comments

1

Use

Session["me"] = TextBox1.Text;

and use it before redirecting to other page

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.