In moving to ASP.NET from classic ASP and ColdFusion, one of the first things that I had to adjust to was developing using only one form within a web page. This isn’t a true limitation, to be accurate, WebForms supports only one server-side form per web page but technically, there can still be multiple HTML forms on the page, the additional forms simply are not able to participate in the ASP.NET WebForms Framework.

<form runat="server">

    <!-- a lot of magic here -->

</form>

The aim, I believe, is to provide state and events in the world of web application development that are similar to what we are accustomed to with WinForms application development. So with WebForms we are provided with the concepts of viewstate and postback events, which are raised by other server-side form elements such as buttons, written as:

<asp:Button ID="MyButton" OnClick="MyButton_Click" runat="server">

Since adopting ASP.NET MVC3 I’ve been reunited with HTML form elements and I find myself enjoying the flexibility of multiple forms per page by design and not necessarily a hack. As written in Pro ASP.NET MVC3 Framework, Third Edition, “…there are no ViewState or other hidden form elements, and the ID values you assign to IDs don’t get mangled”. So not to travel down memory lane on this one, but it is nice to write HTML and JavaScript (or should I say jQuery script) without wrestling with the nuances of WebForms. Now with the wide implementation of data attributes in HTML5 elements by browsers, markup semantics have become cleaner as well. So now markup such as this:

<div id='<%= MyLogicalValue1 %>_<%= MyLogicalValue2 %>'
    onclick="javascript:MyFunction(this.id);">

    <!-- display information -->

</div>

Can be better represented as:

<div id="MyDiv" data-url="/mydestination.aspx"
    data-value1='<%= MyDataValue1 %>'
    data-value2='<%= MyDataValue2 %>'>

    <!-- display markup here -->

</div>

Of course JQuery provides some convenient methods for enumerating and working with the data values; and although this was merely a short and dirty “how-to”, data attributes can also be expressed in JSON notation, as a collection of properties and values, instead of a data attribute for each value that you would like to represent.

In any case…it’s a good time to be a developer. All of the once so complicated concepts that we had to work around are all trivial implementations of semantics now.

Comments


Comments are closed