Javascript for disabling dropdown in ASP.NET

Posted by Lijo on Stack Overflow See other posts from Stack Overflow or by Lijo
Published on 2010-04-09T18:52:24Z Indexed on 2010/04/09 18:53 UTC
Read the original article Hit count: 144

Filed under:

Hi Team,

I am using JScript in ASP.NET 2005. I have a page with a checkbox and a dropdown list. When the checkbox is checked the dropdown is to be disabled. During Postback of the page this should be retained. I am using a javascript function as follows

if((chkOwner[1].checked==true)) {

document.getElementById(ddlClientID).disabled=true;

document.getElementById(ddlClientID).className = "form-disabled";

document.getElementById(ddlClientID).selectedIndex = 0; }

else {

  document.getElementById(ddlClientID).disabled=false;

  document.getElementById(ddlClientID).className = "form-input";

  document.getElementById(ddlClientID).selectedIndex = 0;

}

This works, almost. However, the dropdown selection is not retained after postback (when checkbox is not selected).

Apprently the solution is to remove the last line, i.e, in the else part, remove the selectedIndex =0 setting.

But, when I do that the disabling of dropdown (when check box is selected) is not working after post back.

Could you please help on this?

Thanks

Lijo

© Stack Overflow or respective owner

Related posts about ASP.NET