开发者

Disable a checkbox in javascript and recognize it as checked on the server side

I have a checkbo开发者_JAVA技巧x which in some cases may be disabled and checked using javascript, i.e:

var cbTest = document.getElementById("CheckBoxTest");
cbTest.disabled = true;
cbTest.checked = true;

However, when sending a postback, CheckBoxTest.Checked is false on the server side.

Is it possible to disable the checkbox and still have the server side recognize it as checked?


Any disabled control inside a form will not submitted to server on post back. You can add a hidden input control and put the checkbox state to that input and server side check that hidden input value.


To get a disabled field's value you'll have to enable it just before the postback. The avalue of a disabled field is never send.


You can either enable the checkbox before the post, or set up a hidden field to hold the value of the checked state. A disabled control won't post its value.


I think that HTML forms only post the values of enabled controls. I guess one way around this would be to have a hidden field (<input type="hidden"/>), and to store the Checked status of the CheckBox in here.


Have you tried to get the Attribute like

string val = checkbox.Attributes["checked"].ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜