Hi,
I'm trying to learn web form design using Visual Studio, Visual Basic.NET, ASP.NET and javascript. I've noticed some odd behavior when I change disabled ASP form controls using javascript functions. I'm trying to dynamically alter the controls on the form depending on input from the user by using client-side javascript rather than requiring postbacks and VB code on the server. However, when I change a disabled control using javascript, it reverts back to the prior state after the form is submitted and posted back(postbacked?). All my ASP controls have runat=”server”.

Here’s the simplest example of the problem:

The form includes two ASP text boxes, txtBirthDate and txtAge, where txtAge is disabled and set=”xx” in the initial pass through Page_Load. When the user enters a date in txtBirthDate and tabs to next field, I have OnBlur event linked to a javascript function that computes age and puts the value in txtAge. This works fine. When the form is submitted or some other control triggers a postback, I do not reset or clear any of the fields but for some reason the txtAge field reverts to “xx”. This example is trivial but there are other cases where controls toggle between disabled and enabled and the setting changes after submit/postback. Those cases are more annoying.

The problem with txtAge reverting to previous value can be eliminated by setting txtAge to enabled. Then when my javascript function puts the age value in the txtAge box, the value remains after submit/postback. Also, if I use autopostback and set the age value in a txtBirthDate_TextChanged event, the value remains after submit. But, I would rather not do that.

I can sort of accept the fact that maybe javascript execution might not be recognized by ASP/VB and the values would get reset after each postback. However, I’m very confused by the fact that this problem only occurs with DISABLED controls and not with enabled ones.

Any suggestions?

Thanks,
Pat G.