Reputation: 2727
My code:
protected void Button1_Click(object sender, EventArgs e)
{
CustomControl myControl = new CustomControl();
UpdatePanel1.ContentTemplateContainer.Controls.Add(myControl);
Button btn = new Button();
UpdatePanel1.ContentTemplateContainer.Controls.Add(btn);
}
After click new button appears but my control did not. CustomControl if fine(?) since I can add it into .aspx file and it work without any problem.
What did I wrong?
btw. There is no errors or warnings, it just don't add custom control to html page.
Upvotes: 1
Views: 153
Reputation: 2727
I found a solution based on discussion from related topic.
now is:
CustomControl myControl = new CustomControl();
should be:
string controlPath = @"~/Controls/CustomControl.ascx";
CustomControl myControl = (CustomControl)LoadControl(controlPath);
Upvotes: 1