SubmitDisabledControls - A New Property in ASP.NET 2.0

Published 23 January 06 01:37 PM | Scott Mitchell

Last week I blogged about the differences between read-only and disabled HTML elements, the main one being that read-only controls' values are posted back to the server on form submission, while disabled controls' values are not. With ASP.NET 2.0, the behavior changes slightly such that the ASP.NET TextBox, when its ReadOnly property is True, will not pick up any changes to the value it sent down to the client. This change in behavior can introduce a subtle bug for those relying on that behavior, as evidenced by this blog entry by Rick Strahl.

One of the issues with disabled controls is that if controls are marked disabled on the client-side, the values are not posted back and therefore any changes are lost from the previous visit. To demonstrate this, check out this demo. ASP.NET 2.0 adds a new property to the HtmlForm class (the server-side Web Form) that it designed to mitigate this problem. When set to True, the SubmitDisabledControls property injects a morsel of JavaScript in the <form> element's onsubmit event handler that sneakily goes in and marks all disabled form fields as enabled, in order to have their form values returned by the browser on postback. This property, as well as other workarounds to this problem (for those still in ASP.NET 1.x), are discussed in greater detail in my latest 4Guys article, Subtleties in Providing a Read-Only User Interface.

Filed under:

Comments

No Comments

Archives

My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.