yazanpro
yazanpro

Reputation: 4762

Changing a Property of a control in Javascript does not take effect When Reading from ASP.NET

I have a button that is linked to a checkbox via a javascript code, meaning that when the checkbox is checked, the button is enabled and vise versa. The initial value of the button (in ASP markup) is disabled, as well as the chekbox

Now when postback, whichever the button is enabled or not (after playing in javascript), the button is read as (enabled false) in server side (which is the initial value) can I read the last client-side .disabled value of the button from within ASP.NET (server side)? If so I can assign the client-side value (the real value of the button) to the server side 'enable' property.

Upvotes: 0

Views: 870

Answers (1)

patil.rahulk
patil.rahulk

Reputation: 584

All asp.net controls are initialized using their earlier states when a postback happens. THat means the enabled="false" value will be used to reinitialize the button control when your page postback happens. So the enabling done by your javascript code will not have any effect there.

You will have to make some tweaks to your code so that this can be achieved.

  1. create a hiddenfield on your page
  2. set a value in the textbox 1/0 OR true/false whenever you are trying to enable/disable the button.
  3. in your page_load ()

if(ispostback){ //read the value of the hidden control and set the enabled/disabled property of the button accordingly. }

Upvotes: 1

Related Questions