locked
Session variable values dropping RRS feed

  • Question

  • Hi

    I'm new to c# and could use a little guidance.

    I'm pulling in a regular text form field from a page in the code behind

        protected void Page_Load(object sender, EventArgs e)
        {
    	string GetPassbasket = Request.Form["PassBasket"];
    	Response.Write(GetPassbasket);
    	Session["PassCart"] = GetPassbasket ;
    	Response.Write("<br/>PassCart: " + Session["PassCart"]) ;
        }

    which looks like it's setting the session values. However when I move through to the next part it's dropping the string held.

    If I give the session a value like

    Session["PassCart"] = "My session";

    it carries over correctly.

    I'd be very grateful if someone could point me in the right direction!!

    Cheers

    Grant

    Thursday, June 25, 2015 12:37 PM

Answers

  • ASP.NET issues can be discusssed at the ASP.NET forum.

    http://forums.asp.net/

    • Marked as answer by Just Karl Thursday, July 9, 2015 10:52 PM
    Thursday, June 25, 2015 1:17 PM
  • Thank you for your trouble - much appreciated - however it hasn't solved my issue - I have now asked in the correct place!
    • Proposed as answer by Kristin Xie Friday, June 26, 2015 7:22 AM
    • Marked as answer by Just Karl Thursday, July 9, 2015 10:52 PM
    Thursday, June 25, 2015 2:36 PM

All replies

  • ASP.NET issues can be discusssed at the ASP.NET forum.

    http://forums.asp.net/

    • Marked as answer by Just Karl Thursday, July 9, 2015 10:52 PM
    Thursday, June 25, 2015 1:17 PM
  • You should indeed be asking asp.net questions in the appropriate forum.

    .

    Rather than guess exactly what you're doing here's some markup:

            <div>
             <P>Pass Cart:<asp:TextBox ID="PassCart" runat="server"></asp:TextBox>  </P>
             <P> <INPUT TYPE=SUBMIT>  </P>
             <P> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></P>
            </div>

    Code

            protected void Page_Load(object sender, EventArgs e)
            {
                if (IsPostBack)
                {
                    Session["PassCart"] = PassCart.Text;
                }
                Label1.Text = Session["PassCart"] as string;
            }

    Things in session are objects.

    There are two page loads happen, going and coming back.

    If that's news then you need to read up on the page lifecycle.

    It's complicated, particularly with master pages.


    Hope that helps.

    Technet articles: WPF: Change Tracking; All my Technet Articles

    Thursday, June 25, 2015 1:51 PM
  • Thank you for your trouble - much appreciated - however it hasn't solved my issue - I have now asked in the correct place!
    • Proposed as answer by Kristin Xie Friday, June 26, 2015 7:22 AM
    • Marked as answer by Just Karl Thursday, July 9, 2015 10:52 PM
    Thursday, June 25, 2015 2:36 PM