Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I am using Html Helper.Now i want to disable My textbox on checkbox checked is true.My View is as follows.

@using (Html.BeginForm())
{
<fieldset>
<legend>
Login 
</legend>
    <div>
    @Html.LabelFor(m => m.user_name)
    @Html.TextBoxFor(m=>m.user_name)
    @Html.ValidationMessageFor(m=>m.user_name)
    </div>

   <div>
     @Html.CheckBoxFor( m=>m.Active)
     @Html.ValidationMessageFor(m=>m.Active)
    </div>



How to Disable UserName Textbox If checkbox is checked..Plz help.
Posted
Updated 15-Feb-14 1:43am
v3
Comments
Sampath Lokuge 15-Feb-14 7:31am    
Do you need to disable the text box at the time when you load the form or after the form loads ?
Member 10435696 15-Feb-14 7:39am    
Yes i want textbox disabled at load time.then when checkbox change to true then textbox get enabled & vice versa

According to your check box's status, disable the text box is as below.

@Html.TextBoxFor(m=>m.user_name, new { @readonly="readonly" })


When click the check box use below mentioned JS code.

$("#YourTextBoxId").removeAttr('readonly');


Note:Here you have to find the Id of the text box by using chrome dev tool.
 
Share this answer
 
v3
Comments
Member 10435696 15-Feb-14 7:52am    
This disables textbox on load..Now when checkbox checked is true then my textbox doesnt enable..???
Sampath Lokuge 15-Feb-14 7:54am    
Are you using jQuery with your project ?
Member 10435696 15-Feb-14 7:56am    
Yes i am..In view how to use jquery..plz help
Sampath Lokuge 15-Feb-14 8:01am    
I have updated my answer.Please check that.
 
Share this answer
 
Comments
Member 10435696 18-Feb-14 4:39am    
Plz Have a Look
http://www.codeproject.com/Questions/729408/Consume-data-from-wcf-client-in-current-applicatio

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900