views:

1156

answers:

2

I have a form in which the user can choose a component type from a combo box, and depending on that component they they may or may not be able to choose a data type from another combo box.

When the user selects a component type, client-side javascript fires on the change and sets the value of the data type combo box if required and disables the data type combo box if required. Here's the strange thing: when that form submits the server-side gets the value of that data type combo box and it's not what I set it to!

I've seemingly narrowed it down to one line of javascript:

document.all("cmbDataType").disabled = true;

If that line is commented out, it still gets set to the right value based on the component type but not disabled, and the form submit gives the correct value to the server based on the value that the client chooses.

If that line executes, then despite the user seeing the correct value in that disabled combo box, the value returned to the server is not correct.

I haven't been able to find anyone else with the same problem, so I hope it's not something super-weird. Browser is IE7, webapp is ASP.NET 2.0. Thanks for looking!

+2  A: 

The reason this is happening is that ASP.NET 2.0 doesn't submit the values of disabled controls by default. (More accurately, it doesn't update the server control values on post back.) You can override that by putting the following line in your Page_Load event:

Page.Form.SubmitDisabledControls = true;

Or you could set the value in the form tag:

<form id="myForm" runat="server" SubmitDisabledControls="true">
Jeromy Irvine
Thank you very much! I never knew that tidbit, and setting that form tag value fixed it straight away!
Coxy
A: 

How can I emulate this functionality in Framework 1.1?

Thank you,

Debby

This is actually an HTML limitation that the ASP.NET framework works around. Google for "submit disabled controls", or try adding a "readonly" token to your controls.
overslacked