Javascript for disabling dropdown in ASP.NET
<p>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 behavior should be retained.  I am using a javascript function as follows</p>

<pre><code>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;
}
</code></pre>

<p>This works, almost. However, the dropdown selection is not retained after postback (when checkbox is not selected). [It goes to zero index's value]</p>

<p>Apprently the solution is to remove the last line, i.e, in the else part, remove the selectedIndex =0 .</p>

<p>But, when I do that the disabling of dropdown (when check box is checked) is not working after post back.</p>

<p>Could you please help me on this?</p>

<p>More Info: I am using ClientScript.RegisterStartupScript for checking this at each page load.</p>

<p>Thanks</p>

<p>Lijo </p>

<p>--CODE-----
Following is what I am trying. (This is a sample application I created just now. It does not work. This can only show what I am trying to achieve.)</p>

<pre><code> function ManageInputsFor()
 {  
        if((document.getElementById(chbx).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; 
        }
 }

 protected void Page_Load(object sender, EventArgs e)
    {
        ClientScript.RegisterClientScriptBlock(Page.GetType(), "chbx", @"&lt;script language=""javascript"" type=""text/javascript""&gt;var chbx ='" + CheckBox1.ClientID + "'&lt;/script&gt;");
        ClientScript.RegisterClientScriptBlock(Page.GetType(), "ddl", @"&lt;script language=""javascript"" type=""text/javascript""&gt;var ddlClientID ='" + DropDownList1.ClientID + "'&lt;/script&gt;");
        ClientScript.RegisterStartupScript(Page.GetType(), "onLoadCallForManageInputs", @"&lt;script language=""javascript"" type=""text/javascript""&gt;ManageInputsFor();&lt;/script&gt;");

        CheckBox1.Attributes.Add("onclick", "ManageInputsFor();");

    }
</code></pre>
