开发者

Programatically instantiate and add controls to UpdatePanel

I'm creating a specific webpart in Sharepoint and I'm using (or trying to) AjaxToolkit controls. Because of the environment I'm developing on, I can't declaratively write my webpart, so I have to do it all programatically.

I'm trying to add the UpdatePanel, but so far without success.

Here's my code:

internal void CreateMainPanel()
{
    Panel main = new Panel{CssClass="f开发者_如何学JAVAorm"};
    UpdatePanel All = new UpdatePanel();
    All.ContentTemplateContainer.Controls.Add(main);
    //form is a static panel reference which I use inside the class
    form = main;
}

Then I get this message:

[ArgumentNullException: Value cannot be null. Parameter name: child] System.Web.UI.ControlCollection.Add(Control child) +11023974

If I'm understanding it right, the error says my Panel is "null". Why so? I instantiated it right now.

How can I add the UpdatePanel and its controltemplate programatically?

Thanks in advance !


Try add brackets after new Panel:

internal void CreateMainPanel()
{
    Panel main = new Panel(){CssClass="form"};
    UpdatePanel All = new UpdatePanel();
    All.ContentTemplateContainer.Controls.Add(main);
    //form is a static panel reference which I use inside the class
    form = main;
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜