简体   繁体   English

使用Request.Form获取禁用的HTML复选框的值

[英]Getting a value of a disabled HTML checkbox using Request.Form

I have a html checkbox 我有一个HTML复选框

<input type="checkbox" name="MyChkBox" .. />

There is another control that makes this enable/disabled and I am doing that using JQuery 还有另一个控件可以启用/禁用此功能,我正在使用JQuery进行此操作

$(this).attr("disabled", "true");

On the server, I get the checkbox values using: 在服务器上,我使用以下命令获取复选框值:

string info = Request.Form["MyChkBox"];

My problem is if a checkbox is checked and disabled, I need to be able to get this value using Request.Form 我的问题是,如果选中并禁用了复选框,则需要能够使用Request.Form获取此值。

You can't do this, you'll need to re-enable it to see/get it server-side (otherwise the client won't send it at all). 您无法执行此操作,需要重新启用它才能在服务器端查看/获取它(否则客户端将根本不会发送它)。 The browser doesn't include disabled controls in the <form> submission, since they don't count as "successful" controls . 浏览器没有在<form>提交中包含disabled控件, 因为它们不算作“成功”控件

You could have the checkboxes there for display purposes, and have some hidden fields that contain the actual values that are passed to the server. 您可能在此处具有用于显示目的的复选框,并且具有一些隐藏字段,其中包含传递给服务器的实际值。

If the checkboxes ever need to become enabled on the client-side, you can have them change the value of the hidden element onchange , so that the values match. 如果需要在客户端启用复选框,则可以让它们更改隐藏元素onchange的值,以使这些值匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM