views:

61

answers:

3

I have a drop down list that gets enabled/disabled based on a checkbox onclick. On my debugging my object reference is not set when my checkbox is disabled in my controller.

CONTROLLER

Subject = Request.Form["DetailSelect" + rowID].ToString();

JAVASCRIPT

ddlSelect.disabled = !ddlSelect.disabled;

ASPX

<select = id="detailSelect<%=item.rowID"%> name="DetailSelect<%=item.rowID%>">
     <option value="">--Choose One--</option>
     <option value="Math">Math</option>
     <option value="English">English</option>
     <option value="History">History</option>
</select>

Where do I go to disable my drop down list, without using the disabled toggle in javascript?

+1  A: 

If you don't use the disabled property, you can do it with an attribute:

<select ... disabled="disabled"></select>
Matthew Abbott
Is this accessable in the controller with my Request.Form code?
+1  A: 

You can do that via jquery

 $("input[id$='chkbox']").click(function() {  
            $("select[id$='ddl']").attr("disabled", !$(this).is(":checked"));  
       }); }); 

where chkbox is the Id of the checkbox and ddl is the ID of the drop down list

Shruthi
Is this accessable in the controller with my Request.Form code?
There is a nice article which tells us why disabled controls are not posted to the web server and explores some of the workarounds to this problem.http://www.4guysfromrolla.com/articles/012506-1.aspxunder the heading "Fixing the Disabled Form Fields Problem By Using a "Faux" Disabled State"
Shruthi
A: 

I did a little workaround where I used a hidden object and before I disable my drop down in the javascript function, I assign the value to my hidden input.

ASPX

<input id="hiddenSelect" type="hidden" name="HiddenSelect" value="" />

JAVASCRIPT

var ddlSelect = document.getElementById('detailSelect' + rowID).value;
document.getElementById('hiddenSelect').value = ddlSelect;
ddlSelect.disable = !ddlSelect.disabled;