panels and variable state

Discussion in 'ASP .Net' started by Lerp, Jun 2, 2004.

  1. Lerp

    Lerp Guest

    Hi all,

    I was just playing around with some code to hide/show panels and I
    discovered that I am losing a variable's value when my sub is called from a
    button in paneltwo. Why is this?

    Cheers and Thanks, Lerp



    Code below:


    <script language="vb" runat="server">

    Dim myvalue as Long

    SUB Page_Load(Sender As Object, E As EventArgs)
    panelone.visible = true
    paneltwo.visible = false
    END SUB

    Sub One(Sender As Object, E As EventArgs)
    myvalue = 7
    panelone.visible = false
    paneltwo.visible = true
    response.write(myvalue & " IS MY VALUE" & "<BR>")
    End Sub


    Sub Two(Sender As Object, E As EventArgs)
    Dim curVal = myvalue
    panelone.visible = true
    paneltwo.visible = false
    response.write(curVal & " IS CurVal VALUE" & "<BR>")
    ******************************** This turns out to be ZERO

    End Sub

    </script>


    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <head></head>
    <body>

    <form runat="server">

    <asp:panel ID="panelone" runat="server">
    <table width="600" cellpadding="2" cellspacing="0" border="0">
    <tr valign="top">
    <td align="left" class="bodycopy">
    <asp:Button id="submitform1" text="Panel One Button" OnClick="One"
    runat="server" CssClass="but" />
    </td>
    </tr>
    </table>
    </asp:panel>


    <asp:panel ID="paneltwo" runat="server">
    <table width="600" cellpadding="2" cellspacing="0" border="0">
    <tr valign="top">
    <td align="left" class="bodycopy">
    <asp:Button id="submitform2" text="Panel Two Button" OnClick="Two"
    runat="server" CssClass="but" />
    </td>
    </tr>
    </table>
    </asp:panel>


    </form>
    </body>
    </html>
     
    Lerp, Jun 2, 2004
    #1
    1. Advertising

  2. HTTP is stateless. This means that every time a Page Posts back, everything
    is re-initialized. If you change the value of a private member of your class
    in one instance, you have to persist it somehow between PostBacks.
    ViewState, Session, etc.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Big things are made up
    of lots of little things.

    "Lerp" <> wrote in message
    news:...
    > Hi all,
    >
    > I was just playing around with some code to hide/show panels and I
    > discovered that I am losing a variable's value when my sub is called from

    a
    > button in paneltwo. Why is this?
    >
    > Cheers and Thanks, Lerp
    >
    >
    >
    > Code below:
    >
    >
    > <script language="vb" runat="server">
    >
    > Dim myvalue as Long
    >
    > SUB Page_Load(Sender As Object, E As EventArgs)
    > panelone.visible = true
    > paneltwo.visible = false
    > END SUB
    >
    > Sub One(Sender As Object, E As EventArgs)
    > myvalue = 7
    > panelone.visible = false
    > paneltwo.visible = true
    > response.write(myvalue & " IS MY VALUE" & "<BR>")
    > End Sub
    >
    >
    > Sub Two(Sender As Object, E As EventArgs)
    > Dim curVal = myvalue
    > panelone.visible = true
    > paneltwo.visible = false
    > response.write(curVal & " IS CurVal VALUE" & "<BR>")
    > ******************************** This turns out to be ZERO
    >
    > End Sub
    >
    > </script>
    >
    >
    > <html>
    > <head>
    > <title></title>
    > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > <head></head>
    > <body>
    >
    > <form runat="server">
    >
    > <asp:panel ID="panelone" runat="server">
    > <table width="600" cellpadding="2" cellspacing="0" border="0">
    > <tr valign="top">
    > <td align="left" class="bodycopy">
    > <asp:Button id="submitform1" text="Panel One Button" OnClick="One"
    > runat="server" CssClass="but" />
    > </td>
    > </tr>
    > </table>
    > </asp:panel>
    >
    >
    > <asp:panel ID="paneltwo" runat="server">
    > <table width="600" cellpadding="2" cellspacing="0" border="0">
    > <tr valign="top">
    > <td align="left" class="bodycopy">
    > <asp:Button id="submitform2" text="Panel Two Button" OnClick="Two"
    > runat="server" CssClass="but" />
    > </td>
    > </tr>
    > </table>
    > </asp:panel>
    >
    >
    > </form>
    > </body>
    > </html>
    >
    >
     
    Kevin Spencer, Jun 3, 2004
    #2
    1. Advertising

  3. Lerp

    Lerp Guest

    ah man, I knew it....

    I ended up using session vars anyways...thx for help.

    Thx Kevin,

    Cheers, Lerp


    "Kevin Spencer" <> wrote in message
    news:...
    > HTTP is stateless. This means that every time a Page Posts back,

    everything
    > is re-initialized. If you change the value of a private member of your

    class
    > in one instance, you have to persist it somehow between PostBacks.
    > ViewState, Session, etc.
    >
    > --
    > HTH,
    > Kevin Spencer
    > .Net Developer
    > Microsoft MVP
    > Big things are made up
    > of lots of little things.
    >
    > "Lerp" <> wrote in message
    > news:...
    > > Hi all,
    > >
    > > I was just playing around with some code to hide/show panels and I
    > > discovered that I am losing a variable's value when my sub is called

    from
    > a
    > > button in paneltwo. Why is this?
    > >
    > > Cheers and Thanks, Lerp
    > >
    > >
    > >
    > > Code below:
    > >
    > >
    > > <script language="vb" runat="server">
    > >
    > > Dim myvalue as Long
    > >
    > > SUB Page_Load(Sender As Object, E As EventArgs)
    > > panelone.visible = true
    > > paneltwo.visible = false
    > > END SUB
    > >
    > > Sub One(Sender As Object, E As EventArgs)
    > > myvalue = 7
    > > panelone.visible = false
    > > paneltwo.visible = true
    > > response.write(myvalue & " IS MY VALUE" & "<BR>")
    > > End Sub
    > >
    > >
    > > Sub Two(Sender As Object, E As EventArgs)
    > > Dim curVal = myvalue
    > > panelone.visible = true
    > > paneltwo.visible = false
    > > response.write(curVal & " IS CurVal VALUE" & "<BR>")
    > > ******************************** This turns out to be ZERO
    > >
    > > End Sub
    > >
    > > </script>
    > >
    > >
    > > <html>
    > > <head>
    > > <title></title>
    > > <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    > > <head></head>
    > > <body>
    > >
    > > <form runat="server">
    > >
    > > <asp:panel ID="panelone" runat="server">
    > > <table width="600" cellpadding="2" cellspacing="0" border="0">
    > > <tr valign="top">
    > > <td align="left" class="bodycopy">
    > > <asp:Button id="submitform1" text="Panel One Button" OnClick="One"
    > > runat="server" CssClass="but" />
    > > </td>
    > > </tr>
    > > </table>
    > > </asp:panel>
    > >
    > >
    > > <asp:panel ID="paneltwo" runat="server">
    > > <table width="600" cellpadding="2" cellspacing="0" border="0">
    > > <tr valign="top">
    > > <td align="left" class="bodycopy">
    > > <asp:Button id="submitform2" text="Panel Two Button" OnClick="Two"
    > > runat="server" CssClass="but" />
    > > </td>
    > > </tr>
    > > </table>
    > > </asp:panel>
    > >
    > >
    > > </form>
    > > </body>
    > > </html>
    > >
    > >

    >
    >
     
    Lerp, Jun 3, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Ruegsegger

    SmartNavigation and Panels causing debug error

    Chris Ruegsegger, Aug 6, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    462
    Yan-Hong Huang[MSFT]
    Aug 8, 2003
  2. Richard Fennell

    asp:listbox, panels and z-order

    Richard Fennell, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,243
    Richard Fennell
    Aug 27, 2003
  3. Miguel Dias Moura

    Make panels visible and invisible.

    Miguel Dias Moura, Jun 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    12,594
    Ireney Berezniak
    Jun 21, 2004
  4. Mark Rae

    <asp:Panels, borders and HTML tables

    Mark Rae, Oct 6, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    5,038
    Mark Rae
    Oct 6, 2004
  5. Paul Mason

    panels and page control...

    Paul Mason, Feb 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    296
    bruce barker
    Feb 4, 2005
Loading...

Share This Page