I don't know what the problem might be Gerard ... here's what I did and it works just fine:
Here's Page1:
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
Session["MyVar"] = this.TextBox1.Text;
Response.Redirect("Page2.aspx");
}
}
Here's Page2:
public partial class Page2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string bob = Session["MyVar"].ToString();
this.TextBox1.Text = bob;
}
}
What did you do differently?
~~Bonnie
>Hi Bonnie.. thanks for your reply.
>
>I dont seem to be able to get these session variables to work !!
>
>I have a Page1 , on click event of a button that calls Page2 as follows:
>Session["sesuserid"] = txtUserId.Text;
>
>Page 2 is displayed ok and OnLoad I have:
>string struserid;
>struserid = (string)Session["sesuserid"];
>txtUserId.Text = struserid;
>
>On the txtUserIdText, nothing appears.
>
>Regards,
>
>Gerard
>
>
>
>
>
>
>
>
>>Gerard,
>>
>>I'm not an ASP.NET expert, but this should work. Could you post a little more of your code so that it might be easier to spot where you went wrong?
>>
>>~~Bonnie
>>
>>
>>
>>
>>>Hi Carl..thanks for your reply.
>>>The mis-spelling is just in the hread..the app has the correct spelling but still not working.
>>>
>>>Regards,
>>>Gerard
>>>
>>>
>>>>Note that this line appears to have the Session name spelled incorrectly (it's missing the "y" at the end of "sesCompan"):
>>>>
>>>>
string MyText = (String)(Session["sesCompan"]);
>>>>
>>>>
>>>>
>>>>>Hi.
>>>>>I hve two forms, Form1 and Form2
>>>>>On a Link Button on Form1 I have:
>>>>> Session["sesCompany"] = "Green";
>>>>>
>>>>>On Form2, I just have one TextBox (TextBox1) and on Load of the form I Have:
>>>>> string MyText = (String)(Session["sesCompan"]);
>>>>> TextBox1.text = MyText;
>>>>>
>>>>>But nothing is appearing on the textbox when the form displays !!
>>>>>
>>>>>Anybody have any ideas on whats happenong.
>>>>>regards,
>>>>>Gerard