0

I am a bit new to user controls. my user control class is ucDefault . I dont have any constructors explicitly specified . I have to load my user control with the default constructor . How can i do it ?

Kuntady Nithesh
  • 11,371
  • 20
  • 63
  • 86

1 Answers1

2

Try,

Control control=LoadControl("~/UserControlFile.ascx");

My answers of threads posted by you:

  1. How to load a web usercontrol from a physical path rather than a virtual path
  2. Loading web user controls from blob storage in asp.net

Edit:

Here is a TestControl.cs located at App_code

public class TestControl : UserControl
{
    public TestControl() { }
    public TestControl(string message)
    {
        SayHello = message;
    }
    public string SayHello { get; set; }

    public override void RenderControl(HtmlTextWriter writer)
    {
        base.RenderControl(writer);
        writer.Write(SayHello);
    }
}

and code to loads/creates a control object:

TestControl tc = (TestControl)LoadControl(typeof(TestControl), new object[] { "Hello Buddy" });
Community
  • 1
  • 1
KV Prajapati
  • 93,659
  • 19
  • 148
  • 186