I have some JavaScript to toggle a dropdownlists in a ASP.NET page , which gets called when I click a button. I have like 4-5 dropdownlist/Toggle button pair. Each toggle button toggles the enable/disable property on the associated dropdownlist.
I save the disabled property value of a hidden field to track the disabled state of a button between postbacks, with the following javascript
function disableButton(dropdownID)
{
var element = document.getElementById(dropdownID); // get the DOM element
var trackingField = document.getElementById("_tracking" + dropdownID);
if (element) {
trackingField.value = element.disabled;
//sending the element.disabled instead of "!element.disabled" since we are
//setting dropdownlist.enabled property so is already negated for us
element.disabled = !element.disabled; // invert the boolean attribute
}
return false; // prevent default action
}
HTML
<input type="hidden" name="_trackingdropdownlist" id="_trackingdropdownlist" value="true" />
Code
if (Request.Params[_trackingdropdownlist] != null)
{
bool val = true;
bool.TryParse(Request.Params[_trackingdropdownlist], out val);
dropdownlist.Enabled = val;
}
So the state of the dropdownlist are maintained on the first postback round trip but after that all the dropdownlist get enabled. What is going wrong here?
*Note: The default enabled property value on these dropdownlist are false.