Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
122 views
Welcome To Ask or Share your Answers For Others

1 Answer

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...