how to disable html field on client, and see that change on server

  • Thread starter Thread starter sonic
  • Start date Start date
S

sonic

I realize that if a field is disabled, its value will not be posted to
server.
i realize that .Enabled = false, produces disabled="disabled" markup

i still don't see a good way to disable a field using javascript and
than check for that on the server.

if i render a regular textbox
<asp:Textbox id="txt" runat="server" />
than on client do:
txt.disabled = true; // this disables the control correctly.
than on server
txt.Enabled is true
txt.Attributes.Count is 0

if I do this on the server
txt.Attributes.Add("disabled","false");
it renders to client and is available on postback, but if i change the
value on the client to false, it does not see the new value ( because
http postback does not read values of disabled fields ) but how do i
figure out on server if an element was enabled/disabled by javascript?
 
but how do i
figure out on server if an element was enabled/disabled by javascript?

client side scripting can't talk to server side scripting directly. There is
no connection between the two.

What you can do is pass client side information back to the server via form
data.

So, one option is to use a hidden field, populate the value of that field
via javascript when you diable the other element, and then read that value
client-side on postback.

A bit of a hack, but pretty much the only way to get client side javascript
to communicate with the server side logic.

-Darrel
 
well that wasnt my question but since you replied, hidden field is not
the only way for JS to communicate with ther server...
you can use xmlhttprequest object to talk to server directly, or use
iframe to discretly postback and get server values back to your page
objects, or you can use the query string on regular postback
 
Back
Top