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">
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.
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");
Write the following line in the .cs file
ListBox.Attributes.Add("disabled", "true");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With