禁用后,asp.net文本不发送值 [英] asp.net text doesn't send value when disabled

查看:76
本文介绍了禁用后,asp.net文本不发送值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用jQuery启用和禁用文本框,效果很好.禁用的文本框中有值.但是我面临的问题是,禁用的文本框不会将值传递给服务器.当我使用jQuery启用它时,我在后面的代码中看到了文本框值(调试模式).为何会发生这种情况的任何想法,或者从背后的代码中从禁用的文本框中获取价值的替代方法.

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 规范指出,禁用的输入标签被认为是无效的,不应提交.

The W3 spec says that input tags that are disabled are considered invalid and should not be submitted.

相反,请使用readonly属性:

<input type="text" readonly />

或使用jQuery:

$("#<%=txtUniqueNo.ClientID%>").attr('readonly', 'readonly');

更新:

请根据需要查看如何删除readonly属性: http://jsfiddle.net/ynevet/84HrM/

Look how to remove the readonly attribute if needed: http://jsfiddle.net/ynevet/84HrM/

这篇关于禁用后,asp.net文本不发送值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆