Results 1 to 10 of 10

Thread: Session from a user control?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049

    Question Session from a user control?

    I have an app with some user controls. When I send this information (session("test") = txtTest.text) to a new page using Server.transfer everything works fine. My problem is that when I click Back the txtText.text is reloaded and the entered value is gone. What goes wrong? Is it something I can prevent by settings in the web.config?
    I am using VS2002, could that be the reason?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    If you're just clicking Back, the page state was lost so you'll need something like the following in the page load(and remember to check for "if not page.ispostback"):
    VB Code:
    1. txtTest.Text = Session( "test" )

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Hi PVB, I have tried that as well, but it doesn't help

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    post some code(the piece that assigns the session var and the server.transfer), maybe it's somethin with how you're assigning the session var. And you're inside visual studio when you do this? if you are does the same thing happen when you use a stand alone browser?

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Yes, I have tried to run the form directly, but the same thing happens. I have attatched my code.
    Attached Files Attached Files

  6. #6
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    hmm, well i actually couldn't get your project to not work, but try this in the code behind for page1a.aspx:
    VB Code:
    1. Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
    2.         'CODEGEN: This method call is required by the Web Form Designer
    3.         'Do not modify it using the code editor.
    4.         InitializeComponent()
    5.         If Not Page.IsPostBack And Not Session("teksten_i_textbox1") Is Nothing Then
    6.             Me.TextBox1.Text = Session("teksten_i_textbox1")
    7.         End If
    8.     End Sub

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    I have an idea of that the reason why it doesn't work is that I am using VS2002 Pro. One of my collegues is using VS2003 and then the code works fine

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2001
    Location
    Denmark
    Posts
    1,049
    Doesn't work either.
    Are you using VS2003 Pro?

  9. #9
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    yes i am but i ran that outside of the editor.

  10. #10
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267
    System.Web.HttpContext.Current.Session["var"]/("var") is always a good idea. If you have trouble, or your in a weird place and you don't know where to find the Session. It is exactly what it implies the Current.Session/Request/Response/Server....

    Also, EnsureChildControls() will make sure that the page and all it controls exist and can be accessed. Well it should.

    n/m I'm a dork. That won't help.
    Magiaus

    If I helped give me some points.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width