SubmitDisabledControls - A New Property in ASP.NET 2.0

Posted by: Scott on Writing, on 23 Jan 2006 | View original

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.

Advertisement

Similar Posts

  • August 9th ASP.NET Link-Listing more
  • Blogging from Tech Ed 2006 - Stefan Shakow on ASP.NET - level 400 more
  • [SQL] Change Logical Filenames more
  • Introducing CaptainHook - A Subversion Hook Framework For .NET more
  • CS Dev Guide: User Roles more
  • Why ASP.NET 2.0 Login control doesn't work with SQL Membership provider? more
  • PowerShell and AppPool Names more
  • WPF at Vermont.NET on Monday night AND the Adapter Pattern AND awesome raffles! Lucky us! more
  • Secure ASP.NET Columns for asp.netPRO more
  • Cross Page Posting in ASP.NET 2.0 more

News Categories

.NET | ADO.NET | Agile | Ajax | Architecture | ASP.NET | BizTalk | C# | Certification | Community Server | dasBlog | DataGrid | DataSet | Debugger | DotNetNuke | Events | GridView | IIS | Indigo | JavaScript | Mobile | Mono | Patterns and Practices | Performance | Podcast | Refactor | Regex | Security | Sharepoint | Silverlight | Smart Client Applications | Software | SQL | VB.NET | Visual Studio | W3 | WCF | WinFx | WPF | WSE | XAML | XLinq | XML | XSD