tags:

views:

949

answers:

4

I have a input checkbox that is checked and disabled when some JS runs on page load.

<input name="selectUnionDues" id="selectUnionDues"  type="checkbox" checked="checked" runat="server" />

When I get the value of the checkbox by using (on the server side)

this.selectUnionDues.checked //returns false

I always get a false

EDIT: I am concerned about using heavy asp.net controls since the page size in this application needs to be low. Is there a way out using HTMl controls?

A: 

I get less than intuitive behavior as well. If I test the value in Page_Init, it always returns true. Testing it in Page_Load returns the selected value.

Try using a server side control instead of an HTML control with runat=server.

<asp:CheckBox ID="selectUnionDues" runat="server" Checked="true" />

Also, you state "disabled" control but I don't see anything that is disabled in your markup. Either way, better to use a server WebControl.

Andrew Robinson
Between Page_Init and Page_Load there are more page lifecycle methods (which you can override if you want to): LoadViewState and LoadPostData. Both of these might change the values in the controls.
Andrew Shepherd
+4  A: 

Disabled form controls are not "successful controls", that means they values aren't "submitted" at all with your form.

CMS
A: 

If you don't mind relying on JS, you could have a hidden input who's value changes when the checkbox's check property changes and then use that value server side.

Charlino
Btw, I'm guess it wouldn't be a problem relying on JS because JS is what is causing the checkbox to become disabled.
Charlino
A: 

check this out http://www.4guysfromrolla.com/articles/012506-1.aspx

In short, (1)there is a "SubmitDisabledControls" property of "form" or (2)tweak the javascript the author provided

Might