469,619 Members | 1,885 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,619 developers. It's quick & easy.

Disabled Panel control loses values

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>
Nov 18 '05 #1
5 6719

Robert,

Are you posting back as a result of checking Check1?

If so you might not have the correct value for Check1
during Page_Load -- you would want to enable/disable controls in the
Check1 event that triggers the post back.

Jim
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2
Hi, Robert Phillips,

The cause for the behavior is the browser not posting the values in the
<input type=text disabled> controls. You can try enabling these on the
client side in the onsubmit event or, alternatively, preserve the values on
the server-side (in the Session or in the ViewState maybe) before you set
Enable = false.

Hope this helps
Martin
"Robert Phillips" <ph*************@myfloridahouse.com> wrote in message
news:u4*************@TK2MSFTNGP11.phx.gbl...
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>


Nov 18 '05 #3
I do somthing like that with tables when I hide and show rows. An important thing to remember is that at the end of the Asp.NET rainbow you still come down to HTML markup. If the browser doesent paint it, it doesnt exist anymore to the client or the postback event UNLESS you stuff those values in some kind of server or local storage like cookies, or sessions, or state server. What I do, if your not on a cluster, is when an event is fired that removes a parent control from the presentation, stuff the values into session lik

public void HidePanel(

Session["saveChildControl1"] = objChildControl1.Text; // assuming it's a textbo
Session["saveChildControl2"] = objChildControl2.Text
Session["hasSaveControls"] = "true"
objPanel.Visible = false

then to reload i

public void ShowPanel(

objPanel.Visible = true;
// remember to check if it was hidden as you will bomb on referencing non existant stuf
if (Session["hasSavedControls"] != null

objChildControl1.Text = Session["saveChildControl1"].Text.ToString()
objChildControl2.Text = Session["saveChildControl2"].Text.ToString()

}
Nov 18 '05 #4
i know what you're saying, but if you look at the html generated in my
sample, all of the controls are being generated, but it's intersting that
the div (for the panel) is set to disabled, but the contained TextBox
controls are not (the TextBox control outside the panel does have its html
disabled property set).

the disabled TextBox that isn't in the panel maintains its value fine,
whether or not it is in the posted data.

so, its like asp.net isn't painting it correctly...thus it see it as enabled
during the postback, but no value is avialable in the posted data.

"Harold" <an*******@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
I do somthing like that with tables when I hide and show rows. An important thing to remember is that at the end of the Asp.NET rainbow you
still come down to HTML markup. If the browser doesent paint it, it doesnt
exist anymore to the client or the postback event UNLESS you stuff those
values in some kind of server or local storage like cookies, or sessions, or
state server. What I do, if your not on a cluster, is when an event is fired
that removes a parent control from the presentation, stuff the values into
session like
public void HidePanel()
{
Session["saveChildControl1"] = objChildControl1.Text; // assuming it's a textbox Session["saveChildControl2"] = objChildControl2.Text;
Session["hasSaveControls"] = "true";
objPanel.Visible = false;

}

then to reload it

public void ShowPanel()
{
objPanel.Visible = true;
// remember to check if it was hidden as you will bomb on referencing non existant stuff if (Session["hasSavedControls"] != null)
{
objChildControl1.Text = Session["saveChildControl1"].Text.ToString(); objChildControl2.Text = Session["saveChildControl2"].Text.ToString(); }
}

Nov 18 '05 #5
Hi, Harold,

The problem is with Enabled = {true | false} for the container control.

When you set Visible = {true | false} the child controls keep their values,
so there is no need for this overhead.

Greetings
Martin
"Harold" <an*******@discussions.microsoft.com> wrote in message
news:14**********************************@microsof t.com...
I do somthing like that with tables when I hide and show rows. An important thing to remember is that at the end of the Asp.NET rainbow you
still come down to HTML markup. If the browser doesent paint it, it doesnt
exist anymore to the client or the postback event UNLESS you stuff those
values in some kind of server or local storage like cookies, or sessions, or
state server. What I do, if your not on a cluster, is when an event is fired
that removes a parent control from the presentation, stuff the values into
session like
public void HidePanel()
{
Session["saveChildControl1"] = objChildControl1.Text; // assuming it's a textbox Session["saveChildControl2"] = objChildControl2.Text;
Session["hasSaveControls"] = "true";
objPanel.Visible = false;

}

then to reload it

public void ShowPanel()
{
objPanel.Visible = true;
// remember to check if it was hidden as you will bomb on referencing non existant stuff if (Session["hasSavedControls"] != null)
{
objChildControl1.Text = Session["saveChildControl1"].Text.ToString(); objChildControl2.Text = Session["saveChildControl2"].Text.ToString(); }
}


Nov 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Fabrizio | last post: by
reply views Thread by Niraj via DotNetMonster.com | last post: by
2 posts views Thread by James T. | last post: by
9 posts views Thread by Bill Long | last post: by
3 posts views Thread by Yoavo | last post: by
8 posts views Thread by =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post: by
11 posts views Thread by dongarbage | last post: by
17 posts views Thread by govolsbaby | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.