Problem with CheckListBox

  • Thread starter Thread starter Mau
  • Start date Start date
M

Mau

I have a big problem with the CheckListBox control:
if I disable it and the I enable it I loose
selection (checking) , why?
There is a way to solve this?

Tanks

M

Here some code:

<%@ Page Language="C#" %>
<script runat="server">

void Button1_Click(object sender, EventArgs e) {
CheckBoxList1.Enabled= false;
}

void Button2_Click(object sender, EventArgs e) {
CheckBoxList1.Enabled= true;
}

void Page_Load(object sender, EventArgs e) {
if (!IsPostBack)
{
CheckBoxList1.Items.Add ("1");
CheckBoxList1.Items.Add ("2");
CheckBoxList1.Items.Add ("3");
}
}

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:CheckBoxList id="CheckBoxList1"
runat="server"></asp:CheckBoxList>
</p>
<p>
<asp:Button id="Button1" onclick="Button1_Click" runat="server"
Text="Disable"></asp:Button>
</p>
<p>
<asp:Button id="Button2" onclick="Button2_Click" runat="server"
Text="Enable"></asp:Button>
</p>
</form>
</body>
</html>
 
It's the browser that doesn't post the values of any disabled controls.
The
same happens if you disable a TextBox, RadioButton, etc. It is by design.

So, there is no solution?
:-(
 
Hi,

Mau said:
design.

So, there is no solution?
:-(

Did you read the knowlege base article at
http://support.microsoft.com/?kbid=287738 ? There is a resolution for the
problem which involves some client-side scripting. Another approach may be
storing the selected index in the ViewState when you disable the control and
then setting it back when you enable the control.

Greetings
Martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top