473,574 Members | 18,327 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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....thi s 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(Objec t sender, EventArgs e)
{
if (Check1.Checked )
{
Panel1.Enabled= false;
TestText3.Enabl ed=false;
}
else
{
Panel1.Enabled= true;
TestText3.Enabl ed=true;
}
}
</script>

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

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

<asp:Panel id="Panel1" runat="server" BackColor="gain sboro" 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:CheckBo x 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 6921

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************ *@myfloridahous e.com> wrote in message
news:u4******** *****@TK2MSFTNG P11.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....thi s 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(Objec t sender, EventArgs e)
{
if (Check1.Checked )
{
Panel1.Enabled= false;
TestText3.Enabl ed=false;
}
else
{
Panel1.Enabled= true;
TestText3.Enabl ed=true;
}
}
</script>

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

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

<asp:Panel id="Panel1" runat="server" BackColor="gain sboro" 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:CheckBo x 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["saveChildContr ol1"] = objChildControl 1.Text; // assuming it's a textbo
Session["saveChildContr ol2"] = objChildControl 2.Text
Session["hasSaveControl s"] = "true"
objPanel.Visibl e = false

then to reload i

public void ShowPanel(

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

objChildControl 1.Text = Session["saveChildContr ol1"].Text.ToString( )
objChildControl 2.Text = Session["saveChildContr ol2"].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...thu s it see it as enabled
during the postback, but no value is avialable in the posted data.

"Harold" <an*******@disc ussions.microso ft.com> wrote in message
news:14******** *************** ***********@mic rosoft.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["saveChildContr ol1"] = objChildControl 1.Text; // assuming it's a textbox Session["saveChildContr ol2"] = objChildControl 2.Text;
Session["hasSaveControl s"] = "true";
objPanel.Visibl e = false;

}

then to reload it

public void ShowPanel()
{
objPanel.Visibl e = true;
// remember to check if it was hidden as you will bomb on referencing non existant stuff if (Session["hasSavedContro ls"] != null)
{
objChildControl 1.Text = Session["saveChildContr ol1"].Text.ToString( ); objChildControl 2.Text = Session["saveChildContr ol2"].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*******@disc ussions.microso ft.com> wrote in message
news:14******** *************** ***********@mic rosoft.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["saveChildContr ol1"] = objChildControl 1.Text; // assuming it's a textbox Session["saveChildContr ol2"] = objChildControl 2.Text;
Session["hasSaveControl s"] = "true";
objPanel.Visibl e = false;

}

then to reload it

public void ShowPanel()
{
objPanel.Visibl e = true;
// remember to check if it was hidden as you will bomb on referencing non existant stuff if (Session["hasSavedContro ls"] != null)
{
objChildControl 1.Text = Session["saveChildContr ol1"].Text.ToString( ); objChildControl 2.Text = Session["saveChildContr ol2"].Text.ToString( ); }
}


Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10836
by: Fabrizio | last post by:
Hi, There is any chance to insert a control like a text box in a panel choosing the absolute position? When I try to insert a label , the panel positions the control on a locked position. Thanks Fabrizio
0
1650
by: Niraj via DotNetMonster.com | last post by:
i had put a panel in form and text box,label and numericupdown control in it. Now i had use to send the form as me to some function byref then again from that particular function i use to send the me as f to another function to check some text box which are in pane control. now when i try to check the values of text box if i had edited i...
2
3491
by: James T. | last post by:
Hello! I developed a composite control that inherits from HyperLink and overrides Render method. In web form I am using this control with DataGrid. On DataGrid ItemDataBound event I set ImageWidth and ImageHeight values programmatically. But on post-back the control loses ImageWidth and ImageHeight values. What I am doing wrong?
9
3171
by: Bill Long | last post by:
I have a control that simply displays a list of links. Following one of the links doesn't post back or redirect to another page, it simply hides the current panel and shows the one you selected... So the behavour is similar to a tab control. The user is expected to fill out required data on each of the panels before pressing a submit button...
1
2277
by: Israel | last post by:
The problem: I want to know, definitively when a slider loses focus after a user has started sliding and hasn't released the mouse yet. It appears that this is captured with the WM_ACTIVATEAPP message but this only goes to the form and I want it in the user control that maybe very much removed from the form's knowledge; i.e. the form may...
3
3499
by: Yoavo | last post by:
Hi, I have a ListView control and I make it disabled when a certain event occur. My problem is that when the control become disabled, the selection on the selected item is gone. (I want that the user will still be able to see the selected item). Yoav.
8
5341
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In this code there is a panel panel1, that I populate with a lable in the foreground. Then when I click on "button1" a backgroundworker thread in async...
11
11257
by: dongarbage | last post by:
Hi there, I'm very much a C# novice. How do you do freehand drawing on a panel with a mouse in c#? Thanks, Don
17
10312
by: govolsbaby | last post by:
Is there a way to leave the button forecolor unchanged when it is disabled? I have multiple buttons on the form and depending on various user inputs, some will or will not be enabled but I'd rather their text not go to gray. Thanks.
0
7817
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7833
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6482
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5635
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3759
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3771
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2254
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1082
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.