Monday, May 11, 2009

ActionButton with Controller name and Action name in ASP.NET/MVC

using System.Collections.Generic;
using System.Web;
using System.Web.Mvc;

public static class Action
{
public static string ActionButton(this HtmlHelper helper, string Url, string Text)
{
return GetHtmlBy(Url, Text);
}

public static string ActionButton(this HtmlHelper helper, string ControllerName, string ActionName, string ButtonText)
{
var urlhelper = new UrlHelper(helper.ViewContext.RequestContext);
string virtualpath = string.Format("~/{0}/{1}", ControllerName, ActionName);
string absurl = urlhelper.Content(virtualpath);
return GetHtmlBy(absurl, ButtonText);
}

private static string GetHtmlBy(string Url, string Text)
{
string outputUrl = string.Format(@"
<input type='button' onclick=""javacript: window.location='{1}';"" value='{0}' />", Text, Url);
return outputUrl;
}
}


You can use this ActionButton in aspx file:

<%=Html.ActionButton("ControllerName","ActionName","ButtonText") %>

Thursday, May 7, 2009

Link: ASP.NET 4.0 Webforms Enhancements

Source

More Granular ViewState Control and Webforms Routing

Thursday, April 30, 2009

The Four Pillars of ASP.NET, Web Forms, AJAX, MVC and Dynamic Data.

Source

3. ASP.NET MVC. This pillar is the newest to emerge from Microsoft. In fact, as of this writing, it’s only a couple of weeks old, having been released at Mix09. Some ASP.NET curmudgeons would call this a throwback to the days of ASP “classic” spaghetti code, but for many others--especially the alt.net crowd and transplants from Ruby and Java--this represents the cat’s pajamas on the Microsoft web stack. (Of course, it’s amazing how quickly developers find problems in the latest programmer’s paradise--usually before its release--and I’m sure the MVC aficionados are already looking to the next release.)

The basic idea behind ASP.NET MVC is to separate out the three concerns of the MVC pattern: the model, view, and controller. The model represents the data model, the view is the user interface that presents the data and interacts with the user, and the controller is the command center that takes inputs from the view, pushes and pulls data into/from the model, and decides what to do next. By separating out these concerns (as purely as possible), you improve the ability to create unit tests for your applications and, at least on some level, improve application maintainability. If you are into test driven development, then this is the pillar to hook your horse to.