Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

c# - asp.net text doesn't send value when disabled

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

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

1 Reply

0 votes
by (71.8m points)

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/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...