Conditional disabling is only possible by using JavaScript. First, you need to set an id:
@Html.TextAreaFor(m => m.Changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someId" })
And assuming you use jQuery:
$('#someId').on('keyUp', function() {
var text = $('#someId').val();
if (text.length > 0)
$('#someId').attr('disabled','disabled');
});
I'd like to note, however, that disabling some textbox when the length of it's content is greater than zero, that is, it has any content, just makes no sense, since disabling it will prevent you from modifying it ever again (unless there is some logic that programmatically re-enables it based on some condition).
If your goal is to disable the control if the length of the value on the server is greater than zero (that is, the Changes
property has a not null and non-empty value inside the model), then you could do this:
@if (Model.Changes.Length > 0) {
@Html.TextAreaFor(m => m.Changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someId", disabled = "disabled" })
} else {
@Html.TextAreaFor(m => m.Changes , new { style = " width:97%; height:50px;", tabindex = 5, id = "someId" })
}
If you need to disable it based on a client-side condition, then you can't avoid writing a scipt to do that.