imyoac
imyoac

Reputation: 111

ASP.NET 2.0 project - dynamically generated control based on type?

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...

Upvotes: 0

Views: 138

Answers (1)

hunter
hunter

Reputation: 63512

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 (...)
        { 
            //
        }            
        base.Render(writer);
    }        
}

Upvotes: 2

Related Questions