tags:

views:

65

answers:

2

I have 4 server side ListBox controls. All of them have their Enabled property set to false, yet when rendered they are definitely enabled. They are all multiple select. These have no data binding or any code behind touching them. Below is the markup for all of them (save the ID). I am running v4 of the .NET Framework with IIS6.

<asp:ListBox runat="server" ID="lstProduct" Enabled="false" SelectionMode="Multiple" Rows="6"></asp:ListBox>

Here is the markup that is generated by the runtime:

<select size="6" name="ctl00$ctl00$MainContent$MainContent$lstProduct" multiple="multiple" id="MainContent_MainContent_lstProduct" class="aspNetDisabled">
A: 

Try this:

protected void Page_Load(object sender, EventArgs e)
{
  if (!this.IsPostBack)
  {
   this.lstProduct.Attributes.Add("disabled", "");
  }
}

To remove it you can just remove the disabled tag like this:

this.lstProduct.Attributes.Remove("disabled");
CLaff
A: 

I found a solution. In the <system.web> section of web.config, you must add <pages controlRenderingCompatibilityVersion="3.5">.

With Asp.net 4.0, any control that does not take specific user input (textbox or password), will not be rendered with a disabled="disabled" attribute when Control.Enabled = false is set.

Jacob K