I have to enable and disable the text box using jQuery, which works fine. The disabled text box has value in it. But the issue I am facing is that, the disabled textbox doesn't pass value to server.When I enable it using jQuery, I see text box value in code behind (Debugging mode). Any ideas why this is happening or alternative approach to get value from disabled textbox in code behind.
HTML:
<asp:TextBox ID="txtUniqueNo" runat="server" onkeyup = "OnChange(this)" required/>
Javascript that i use to disable in view page
var inputBox = $("#<%=txtUniqueNo.ClientID%>");
inputBox.prop('disabled', true);
Thanks
The reason is simple, disabled inputs values aren't submitted to the server due to web-browsers submission limitation policy.
The W3 spec says that input tags that are disabled are considered invalid and should not be submitted.
Instead, use the readonly
attribute:
<input type="text" readonly />
Or using jQuery:
$("#<%=txtUniqueNo.ClientID%>").attr('readonly', 'readonly');
UPDATE:
Look how to remove the readonly
attribute if needed: http://jsfiddle.net/ynevet/84HrM/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With