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 ?
Asked
Active
Viewed 2,906 times
1 Answers
2
Try,
Control control=LoadControl("~/UserControlFile.ascx");
My answers of threads posted by you:
- How to load a web usercontrol from a physical path rather than a virtual path
- 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
-
This is using the first overload of LoadControl right? I am asking hw can i do it using the second overload . – Kuntady Nithesh Sep 27 '11 at 06:29
-
Please take a look at this thread - http://stackoverflow.com/questions/240850/asp-net-usercontrol-loadcontrol-issue – KV Prajapati Sep 27 '11 at 06:33
-
Hi , i have added a comment in the thread Loading web user controls from blob storage in asp.net . Can you look at it once ? – Kuntady Nithesh Sep 27 '11 at 07:25
-
i have followed what you have told . But during loading , labels of user control get null values so it throws exception – Kuntady Nithesh Sep 27 '11 at 07:44