Disabled Panel control loses viewstate

Discussion in 'ASP .Net Web Controls' started by Robert Phillips, Apr 28, 2004.

  1. I have a Panel control containing a few TextBox controls. The Panel is
    originally enabled, I enter data into the TextBox controls. When I submit,
    the Panel is disabled during the PostBack and the TextBox controls render
    greyed-out, and I can see the values in the TextBox controls....this is what
    I expected.

    I submit again, the Panel is enabled during the PostBack. All of the
    TextBox controls within the Panel are now enabled, however, the values are
    gone. This doesn't happen with a TextBox control outside of the Panel that
    is also enabled/disabled.

    Is this by design? I have a sample below I am testing with. I have a much
    more complicated form I was going to do this with.

    Also, this doesn't occur when the Visible property is used.


    <%@ Page Language="C#" AutoEventWireup="True" %>


    <script runat="server">

    void Page_Load(Object sender, EventArgs e)
    {
    if (Check1.Checked)
    {
    Panel1.Enabled=false;
    TestText3.Enabled=false;
    }
    else
    {
    Panel1.Enabled=true;
    TestText3.Enabled=true;
    }
    }
    </script>

    <html>
    <head>
    </head>
    <body>

    <form runat="server" ID="Form1">

    <asp:panel id="Panel1" runat="server" BackColor="gainsboro" Height="200px"
    Width="300px">
    Panel1: Here is some static content...
    <asp:TextBox id="TestText" Width="100" Runat="server"></asp:TextBox>
    <p/>
    <asp:TextBox id="TestText2" Width="100" Runat="server"></asp:TextBox>
    </asp:panel>

    <p/><asp:TextBox Runat="server" ID="TestText3" Width="100"/>

    <p/><asp:CheckBox id="Check1" Text="Disable Panel" runat="server" />
    <p/><asp:Button Text="Refresh Panel" runat="server" ID="Button1" />

    </form>

    </body>
    </html>
    Robert Phillips, Apr 28, 2004
    #1
    1. Advertising

  2. Robert, explicitly set the TextBox's in the Panel to disabled (i.e.,
    Enabled = False). That is, change your server-side code to something like:

    > void Page_Load(Object sender, EventArgs e)
    > {
    > if (Check1.Checked)
    > {
    > Panel1.Enabled=false;
    > TestText.Enabled = false;
    > TestText2.Enabled = false;
    > TestText3.Enabled=false;
    > }
    > else
    > {
    > Panel1.Enabled=true;
    > TestText.Enabled = true;
    > TestText2.Enabled = true;
    > TestText3.Enabled=true;
    > }
    > }


    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], Apr 28, 2004
    #2
    1. Advertising

  3. yep, i figured that out later. unfortunately my real form has a lot
    more stuff on it. i'm going the route of looping through the panel's
    controls collection.

    would you consider this an asp.net deficiency?



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Robert Phillips, Apr 28, 2004
    #3
  4. Scott Mitchell [MVP], Apr 28, 2004
    #4
    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. Robert Phillips

    Disabled Panel control loses values

    Robert Phillips, Apr 28, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    712
    Martin Dechev
    Apr 28, 2004
  2. Spam Catcher
    Replies:
    0
    Views:
    584
    Spam Catcher
    Feb 18, 2006
  3. Replies:
    0
    Views:
    1,827
  4. Fahim
    Replies:
    0
    Views:
    474
    Fahim
    Aug 18, 2006
  5. Dwight Johnson
    Replies:
    0
    Views:
    2,719
    Dwight Johnson
    Oct 7, 2008
Loading...

Share This Page