如何在 C# 上以编程方式在 sharepoint 2010 中添加 webpartzone?
我有一个非常简单的问题,但可能很难回答。 如何使用 C# 代码将 webpartzone 添加到我的共享点页面? 我所做的是:我创建了可视化 Web 部件项目并将此代码添加到它的 page_init 事件中:
protected void Page_Init(object sender, EventArgs e)
{
WebPartZone webPartZone1 = new WebPartZone();
webPartZone1.AllowLayoutChange = true;
webPartZone1.EmptyZoneText = "No Data are provided";
webPartZone1.Enabled = true;
webPartZone1.HeaderText = "My Custom Zone";
webPartZone1.Visible = true;
this.Page.Controls.Add(webPartZone1);
}
但它不起作用。但可以让你知道我想要什么。我真的很困惑。
I have a really simple question and probably hard answer.
How to add webpartzone into my sharepoint page using C# code?
What I did is: I create visual web part project and added this code to page_init event of it:
protected void Page_Init(object sender, EventArgs e)
{
WebPartZone webPartZone1 = new WebPartZone();
webPartZone1.AllowLayoutChange = true;
webPartZone1.EmptyZoneText = "No Data are provided";
webPartZone1.Enabled = true;
webPartZone1.HeaderText = "My Custom Zone";
webPartZone1.Visible = true;
this.Page.Controls.Add(webPartZone1);
}
and it's doesn't work. but can give you some idea of what I want. I'm really confused.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为,您正在尝试的有点错误,您正在尝试在 Web 部件中添加 Web 部件区域。我不知道是否可能,但您可以尝试通过母版页的代码来创建它。
我的意思是,您不会将创建的 Web 部件区域控件添加到“this.page”中,而是添加到其主控中。
I think, what you're trying is a bit wrong, you're trying to add a web part zone in a web part. I don't know if it is possible but you can try to create it via code to a master page.
I mean, you will not add the created web part zone control in "this.page" but to its master.