Programming


29
Oct 09

Rendering an ASP.net UserControl to a String

I have been converting one of my side projects from ASP.Net WebForms to ASP.Net MVC.  In order to reuse some of my existing ASP.net UserControls from WebForms in ASP.Net MVC, I tweaked a rending method found here and here.

I improved on these methods by enabling the caller of the utility function to be the one to set properties on the UserControl in a strongly typed fashion. The is no reflection or any other special interface needed on the user control.  The key was adding a callback.

Here is what it looks like to call and render the control to a string by the caller.  In this example I am rendering my GoogleMap UserControl to a string.  The last argument I am passing is an anonymous method that is called by the utility function to initialize my control.

UIUtil.RenderUserControl<GoogleMap>("~/UserControls/GoogleMap.ascx",
    uc =>
    {
        uc.CollegeToShow = CollegeToShow;
        uc.Height = Height;
        uc.Width = Width;
        uc.Mode = Mode;
    });

Continue reading →


28
Jul 09

Twitter Syntax / Commands – Facebook should also support them

Something that amazes me on Twitter, is that regular humans (non-Twitter-Hashtag programmers) are fine with, even good at adding little markup tags in tweets.  So now that we have seen that the masses are cool with adding little tags and markup to freeform content, we should embrace it!

Since Facebook is the leading social network, they should also support a markup syntax in comments & status updates because it is useful for humans and computer programs. Continue reading →