Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

Few days back ASP.NET MVC Framework was released. Since, the framework is new there are not many UI controls available yet! But off course this is all going to change. Actually this has already started to change since Rob Conery created the MVC UI Helper Controls. Scott Hanselman used some of Rob's cool controls in his demo. The purpose of the UI helper controls is to help the developer to quickly create UI controls. So, instead of using the foreach loop to populate a DropDownList you can use the UI helper controls to populate it using a single line of code.

I have not looked at Rob UI Control Library (I am sure it is awesome!) but have made few of my own helper methods. For example to create a TextBox control I can use the following code:

<%= Html.TextBox("mytextBox", "Hello World") %>  

I am extending the Html class and adding my own extension methods (just like Rob did!). My TextBox method looks something like this:

  public static string TextBox(this HtmlHelper helper,string id,string value)
            TextBox t = new TextBox();
            t.ID = id;
            t.Text = value;
            return RenderControlToHtml(t);     

If I want to add a button and attach onmouseover and onmouseout attributes to the button I will use the following code:

  <%= Html.Button("Btn_Submit","Submit","foo()",new ButtonAttribute().Add("onmouseover","'Yellow';")
         .Add("onmouseout"," = 'Blue';"))%>  

And here is the Button method:

 public static string Button(this HtmlHelper helper, string id, string value, string functionName,
           ButtonAttribute attributes)
           Button button = new Button()
               ID = id,
               Text = value,
               OnClientClick = functionName   

           foreach (var key in attributes.Attributes.Keys)
               button.Attributes.Add(key, attributes.Attributes[key]);

           return RenderControlToHtml(button);       


Anyway, I am sure there are lot of MVC controls still to come and it will be very interesting to see how they compete with the ASP.NET server controls.

Posted on Thursday, December 13, 2007 9:37 AM | Back to top

Comments on this post: ASP.NET MVC Framework & Web UI Controls

# re: ASP.NET MVC Framework & Web UI Controls
Requesting Gravatar...
Are you adding this new class inside your own project? Web project like they did in the MVC toolkit or are you extending the toolkit in that you added your own folder int he toolkit and added your class then basically are using the MVCToolkit.dll that you added your new classes in?

How are you structuring your extension classes is what I'm asking and where are you putting them?
Left by anonymous on Feb 25, 2008 6:32 AM

Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: