时禁用asp.net文本不发送值 [英] asp.net text doesn't sends value when disabled
问题描述
我要启用和禁用使用jQuery文本框,工作正常。禁用的文本框有它的价值。但是,我所面临的问题是,残疾人文本框不传递价值server.When我启用它使用jQuery,我看到后面(调试模式)code文本框中的值。任何为什么会这样想法或替代方法以获得在code从背后禁用文本框的值。
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
Javascript that i use to disable in view page
var inputBox = $("#<%=txtUniqueNo.ClientID%>");
inputBox.prop('disabled', true);
感谢
推荐答案
原因很简单,的停用的输入值不会提交到服务器,由于网络浏览器提交的限制政策。
The reason is simple, disabled inputs values aren't submitted to the server due to web-browsers submission limitation policy.
的 W3 的规范说input标签是的停用的被视为无效,不应该被提交。
The W3 spec says that input tags that are disabled are considered invalid and should not be submitted.
相反,使用只读
属性:
<input type="text" readonly />
或者使用jQuery:
Or using jQuery:
$("#<%=txtUniqueNo.ClientID%>").attr('readonly', 'readonly');
更新:
看如何,如果需要删除只读
属性: http://jsfiddle.net/ynevet/84HrM/
Look how to remove the readonly
attribute if needed: http://jsfiddle.net/ynevet/84HrM/
这篇关于时禁用asp.net文本不发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!