1

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?

3 Answers 3

1

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

<select ... disabled="disabled"></select>
Sign up to request clarification or add additional context in comments.

1 Comment

Is this accessable in the controller with my Request.Form code?
1

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

2 Comments

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. 4guysfromrolla.com/articles/012506-1.aspx under the heading "Fixing the Disabled Form Fields Problem By Using a "Faux" Disabled State"
0

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.