1

I am setting and disabling the textbox using jquery. When I click on save and posted to server, I can't see this particular element value.

$('#FirstName').prop('disabled', true);

How can I disable the textbox and post the value to server?

user3477335
  • 165
  • 1
  • 2
  • 12
  • do you use textboxfor for your textbox? if you do then I would recommend using hiddenfor also. that will ensure the value gets returned – Matt Bodily Nov 21 '14 at 21:30
  • I use textboxfor but I don't want to use hiddenfor because I have lot of controls which I need to disable them. – user3477335 Nov 21 '14 at 21:31
  • 3
    Disabled controls do not post back. You could make them readonly instead –  Nov 21 '14 at 21:32

2 Answers2

1

By design disabled form controls are not included in the submitted data. If your aim is to prevent users from changing the set value use readonly instead:

$('#FirstName').prop('readOnly', true);

To make all form fields within a given div, use the following:

$('div :input').prop( 'readOnly', true );
PeterKA
  • 24,158
  • 5
  • 26
  • 48
0

You could possibly use something what Trevor suggested here

$('.container').find('input, textarea, button, select').attr('disabled','disabled');

Fiddle works fine with Chrome/Mozilla/IE 10,9,8

Community
  • 1
  • 1
Shubh
  • 6,693
  • 9
  • 48
  • 83