开发者

Can not add Custom Control into UpdatePanel

My code:

    protected void Button1_Click(object sender, EventArgs e)开发者_C百科
    {

        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.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜