Take the 2-minute tour ×

Working on a legacy ASP.NET 2.0 project.

Anyone know of a free dynamic control that will render itself based upon the type it's assigned to?

For example, if I pass it a DateTime property, it should render as a date time picker. If I give it a string... a simple text box. Give it a list, and it will create a dropdown or listbox...

There has to be something out there...

share|improve this question

1 Answer 1

up vote 2 down vote accepted

I can't image there would be something out there that can just do everything.

You could definitely wrap a lot of controls into one control that you could generically type

public class ControlLoader<T> : System.Web.UI.Control where T : Type 
    public T Value { get; set; }

    protected override void Render(System.Web.UI.HtmlTextWriter writer)
        if (typeof(T) == typeof(DateTime))
            Controls.Add(/* some datetime picker you found */);
        else if (...)
share|improve this answer
Exactly, but I can't find anything... –  imyoac Nov 11 '10 at 19:54
I think this is where I tell you to build this yourself... it really wouldn't be too hard. You could use existing ASP.NET Controls and just load and render them dynamically based on the Type of the data passed in. –  hunter Nov 11 '10 at 19:56
i think he's saying to build it yourself using something like if(typeof(var) == Date) etc. –  dstarh Nov 11 '10 at 20:01
see my updated answer for something that should get you started. –  hunter Nov 11 '10 at 20:01
see i was right :) –  dstarh Nov 11 '10 at 20:01

Your Answer


