0

EXAMPLE

<asp:TextBox ID="txbx" runat="Server" Text="1" Enabled="false" />
  1. A textbox with value '1' is set to disabled.

  2. The texbox value is updated to '2' using javascript.

  3. When posted to the server the intial value '1' is used.

I have tried overwriting this functionality with the following VB Code:

Page.Form.SubmitDisabledControls = True

QUESTION

Why doesn't the updated value post to the server?

NOTES

The updated value post correctly '2' if enabled="true"

<asp:TextBox ID="txbx" runat="Server" Text="1" Enabled="true" />
DreamTeK
  • 32,537
  • 27
  • 112
  • 171

1 Answers1

2

Actually what happens is if you set Enabled = false for some ASP control, that particular control will rendered on client-side but its class will be set as "aspNetDisabled" which prevents its value to be edited. I found no way to edit/change this class. So, you can't edit its value using any client-side script like JavaScript.

When you try to post its value back to server, the initial value is used which was there in server.

If you enable the control, it gets rendered and in that case you can access/edit its value as you want.

Atanu Roy
  • 1,384
  • 2
  • 17
  • 29
  • You can set `style = "display : none" ` instead of disabling it. All JavaScript functions will work perfectly fine in that case. – Atanu Roy Feb 28 '14 at 13:33
  • You are confusing `Enabled` with `Visible`. Disabled controls wil be rendered on clientside, but they don't need to be persisted in `ViewState`. You could use a hiddenfield instead to store the new value, on server you'll use this value for the `TextBox`. – Tim Schmelter Feb 28 '14 at 13:41
  • The value needs to be visible. I have created a followup question here if any of you would like to continue to help. http://stackoverflow.com/questions/22096984/how-to-protect-an-asptextbox-from-user-input – DreamTeK Feb 28 '14 at 13:51
  • I have edited my answer. The problem you explained, I have a work-around for that. I have posted it in the follow-up thread. – Atanu Roy Feb 28 '14 at 13:54
  • This is the answer I came looking for some 7 years later you helped me. – SixOThree Jan 22 '21 at 20:09