Thanks for the reply. The items remain (as far as I can see) in the ComboBox.
I have recreated the problem with the following app. Pressing the Toggle button on the app disables both the TextBox and the ComboBox. Pressing it again enables them both, but only the TextBox is actually rendered as enabled. Debugger shows that the code successfully finds and tries to set the Enabled property of both controls.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication4._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:Button ID="ToggleButton" runat="server" Text="Toggle" OnClick="ToggleButton_Click" />
</div>
</form>
</body>
</html>
using AjaxControlToolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication4
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Init ( object sender, EventArgs e )
{
if (IsPostBack == false)
{
Session.Add( "Toggle", false );
}
TextBox newTextBox = new TextBox();
newTextBox.ID = "NewTextBox";
newTextBox.Text = "This is the text";
form1.Controls.Add( newTextBox );
ComboBox newComboBox = new ComboBox();
newComboBox.ID = "NewComboBox";
form1.Controls.Add( newComboBox );
newComboBox.Items.Add( new ListItem( "Item 1", "Item 1" ) );
newComboBox.Items.Add( new ListItem( "Item 2", "Item 2" ) );
newComboBox.Items.Add( new ListItem( "Item 3", "Item 3" ) );
newComboBox.Items.Add( new ListItem( "Item 4", "Item 4" ) );
}
protected void ToggleButton_Click ( object sender, EventArgs e )
{
bool bEnabled = (bool)Session["Toggle"];
TextBox textBox = (TextBox)form1.FindControl( "NewTextBox" );
if (textBox != null)
{
textBox.Enabled = bEnabled;
}
ComboBox comboBox = (ComboBox)form1.FindControl( "NewComboBox" );
if (comboBox != null)
{
comboBox.Enabled = bEnabled;
}
Session["Toggle"] = !bEnabled;
}
}
}