Results 1 to 4 of 4

Thread: Problem with Session

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    3

    Problem with Session

    Hi, i need help with a little problem about 'Session'

    Look at this piece of code:

    <@ Page Language="VB" EnableSessionState="True" >

    <script runat="server">

    Dim st As String

    Sub Page_Load()

    st="computer"

    Session("mystring")=st

    End Sub


    Sub bt_click(o As Object, e As EventArgs)

    Dim st2 As String = Session("mystring")

    tbox.Text=st2

    End Sub


    </script>


    <form runat="server">

    <asp:Button id="bt1" onclick="bt_click" Text="..." runat="server" />

    <asp:TextBox id="tbox" runat="server" />

    </form>



    When I click the button I´d like to see the word "computer" in the textbox, but nothing appears.
    What is wrong in this code ?
    what I really want is have the changes made to st in the page_load sub, available in the bt_click sub.
    Is there a way to do this without using Session ?

    Thanks


  2. #2
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    I think that the problem may be that you have not set the autopostback property of the button to "true".

    Try :


    Code:
    <asp:Button id="bt1" onclick="bt_click" Text="..." runat="server" autopostback="true"/>
    It might work now.

    Parksie

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2004
    Posts
    3
    It still not working with AutoPostBack="true"

    Thanks

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. Session("mystring")=st
    2.  
    3. 'change to
    4.  
    5. Session.Add("mystring",st)

    In reality however, you should be using viewstate to accomplish this, if its only relative to this individual page.

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