<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Web Controls</title>
        <link>http://wc4f.qsh.es/category/7.aspx</link>
        <description>Web Controls</description>
        <language>en-US</language>
        <copyright>Jeffrey Richardson</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <item>
            <title>Using Controls with ASP.NET MVC ViewPage</title>
            <link>http://wc4f.qsh.es/archive/2009/03/07/9.aspx</link>
            <description>&lt;p&gt;For the last few months, I've been attempting to create WebForm controls specifically designed to work well with ASP.NET MVC and the ViewPage (as well as ViewMasterPage and ViewUserControl). Yesterday, as I near finish with my implementation, I find that &lt;a target="_blank" href="http://weblogs.asp.net/leftslipper/archive/2009/03/03/asp-net-mvc-release-candidate-2-i-declare-myself-to-be-declarative.aspx"&gt;Microsoft has already done so themselves&lt;/a&gt;. However, on second look, it's not finished, though does appear to be a great start.  As I debate whether to finish and bugproof my own implementation, choose to use Microsoft's implementation when they finally have time to finish it, or simply derive Microsoft's current implementation to better fit my needs, I'll describe what I've come up with so far, as a form of public comparison.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;First, my implementation exists in the erroneously named "MvcExtras.Expressions" assembly.  This is a historic naming back when I was attempting to implement everything using only expression builders.  While expression builders are still used, some of the work has been relocated to controls.  I've only implemented four controls; however, combined with the provided expression builders, I'm able to express everything that Microsoft's controls can express, with the exception of a repeater and a drop down list, and express many things that Microsoft's implementation yet cannot.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h4&gt;Controls:&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;Input: This control represents the &amp;lt;input /&amp;gt; HTML element, in all it's types.  By utilizing the Data property along with one of the InputExpressionBuilders, data from the ViewData can be easily obtained. &lt;/li&gt;    &lt;li&gt;Form: This control represents the &amp;lt;form&amp;gt; HTML element. This control is of rare use when using the "self post" design model typically used in ASP.NET MVC. This is mainly a workaround to enable using the UrlRouteExpressionBuilder to set the action attribute of a &amp;lt;form&amp;gt; element, as &amp;lt;form runat="server"&amp;gt; creates an HtmlForm and all of it's WebForm magic that is typically undesirable in ASP.NET MVC. &lt;/li&gt;    &lt;li&gt;ValidationMessage: This control represents the HtmlHelper.ValidationMessage methods.  It contains similar implementation, and results in similar or same behaviour. &lt;/li&gt;    &lt;li&gt;ValidationSummary: This control represents the HtmlHelper.ValidationSummary method. See above. &lt;/li&gt; &lt;/ul&gt;  &lt;h4&gt;Expression Builders:&lt;/h4&gt;  &lt;ul&gt;   &lt;li&gt;InputIdExpressionBuilder: Sets the id, name, and value of an Input control based on the name specified in the expression.  Also, styles the Input control if an error exists in the ModelState. &lt;/li&gt;    &lt;li&gt;CheckIdExpressionBuilder: Sets the id and name of the 'checkbox' type Input control, and specified if the checkbox should be checked. &lt;/li&gt;    &lt;li&gt;InputNameExpressionBuilder, CheckNameExpressionBuilder: Same as above, except the id is not set. &lt;/li&gt;    &lt;li&gt;RadioExpressionBuilder: Sets the name and value of the 'radio' type Input control, and determines from the ViewData if the radio should be checked. &lt;/li&gt;    &lt;li&gt;UrlRouteExpressionBuilder: Generates a URL based on route values specified. &lt;/li&gt;    &lt;li&gt;UrlRouteWithCategoryExpressionBuilder: Same as above, but copies over the "category" route value along with the "controller" and "action" if not explicitly specified. &lt;/li&gt;    &lt;li&gt;ViewDataExpressionBuilder: Represents the ViewData.Eval method. This expression builder is a simple frontend to the ViewData.Eval method. &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;These controls and expression builders do not rely on any external code to work, and the expression builders were built with no-compile pages in mind. Usage is simple as well: the InputData based expression builders simply are assigned to the Input.Data property, while all the others can be used on any property of a string type.&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;h4&gt;Example:&lt;/h4&gt;  &lt;p&gt; &lt;/p&gt;  &lt;div style="font-family: consolas; background: white; color: black; font-size: 10pt"&gt;   &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;asp&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Literal&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;Mode&lt;/span&gt;&lt;span style="color: blue"&gt;="Encode"&lt;/span&gt; &lt;span style="color: red"&gt;Text&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$ViewData: Title &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ValidationSummary&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="text"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Id: username &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ValidationMessage&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;Field&lt;/span&gt;&lt;span style="color: blue"&gt;="username"&amp;gt;&lt;/span&gt;Username is invalid&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;ValidationMessage&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="password"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Id: password &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="checkbox"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Check: rememberMe &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="radio"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Radio: status, invisible &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="radio"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Radio: status, away &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;mvc&lt;/span&gt;&lt;span style="color: blue"&gt;:&lt;/span&gt;&lt;span style="color: #a31515"&gt;Input&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;type&lt;/span&gt;&lt;span style="color: blue"&gt;="radio"&lt;/span&gt; &lt;span style="color: red"&gt;Data&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Radio: status, online &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&lt;/span&gt; &lt;span style="color: blue"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;href&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Url: action=About &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&amp;gt;&lt;/span&gt;About&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

  &lt;pre style="margin: 0px"&gt;&lt;span style="color: blue"&gt;&amp;lt;&lt;/span&gt;&lt;span style="color: #a31515"&gt;a&lt;/span&gt; &lt;span style="color: red"&gt;runat&lt;/span&gt;&lt;span style="color: blue"&gt;="server"&lt;/span&gt; &lt;span style="color: red"&gt;href&lt;/span&gt;&lt;span style="color: blue"&gt;="&lt;/span&gt;&lt;span style="background: #ffee62"&gt;&amp;lt;%&lt;/span&gt;$Url: category=Account, controller=Auth, action=LogOn &lt;span style="background: #ffee62"&gt;%&amp;gt;&lt;/span&gt;&lt;span style="color: blue"&gt;"&amp;gt;&lt;/span&gt;Sign On&lt;span style="color: blue"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="color: #a31515"&gt;a&lt;/span&gt;&lt;span style="color: blue"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;The above is not exactly a real world example one would use, but it should explain how everything fits together.&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;I would release a binary, but it's in an unfinished state at the moment, a few things I've mentioned above are in a state of half implementation; all the right flags get checked, but some are ignored currently when rendering. In the meantime, if I decide my current implementation is worthy of continuing, I'll plan on finishing it up, as well as providing the binary here for others to use as well.&lt;/p&gt;&lt;img src="http://wc4f.qsh.es/aggbug/9.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Jeffrey Richardson</dc:creator>
            <guid>http://wc4f.qsh.es/archive/2009/03/07/9.aspx</guid>
            <pubDate>Sat, 07 Mar 2009 10:16:08 GMT</pubDate>
            <wfw:comment>http://wc4f.qsh.es/comments/9.aspx</wfw:comment>
            <comments>http://wc4f.qsh.es/archive/2009/03/07/9.aspx#feedback</comments>
            <wfw:commentRss>http://wc4f.qsh.es/comments/commentRss/9.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>