以编程方式实例化并向UpdatePanel添加控件

时间:2011-04-04 12:14:20

标签: c# sharepoint web-parts ajaxcontroltoolkit

我正在Sharepoint中创建一个特定的webpart,而我正在使用(或尝试)AjaxToolkit控件。 由于我正在开发的环境,我无法以声明方式编写我的webpart,因此我必须以编程方式完成所有操作。

我正在尝试添加UpdatePanel,但到目前为止还没有成功。

这是我的代码:

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;
}

然后我收到这条消息:

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

如果我理解正确,错误说我的Panel是“null”。为什么这样?我现在就实例化了。

如何以编程方式添加UpdatePanel及其controltemplate?

提前致谢!

1 个答案:

答案 0 :(得分:0)

尝试在新面板后添加括号:

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;
}
相关问题