将 VisualWebPart 实例动态分配给 WebPart 是否可行?

Is it feasible to dynamically assign a VisualWebPart instance to a WebPart?

我正在开发一个需要根据当前用户变形的 WebPart;如果一个人会看到某个控件集合,另一个人会看到其他东西(根据他们的 role/the 情况)。

创建 N 个 VisualWebPart,然后根据当前用户换出 WebPart 承载的特定 VWP 是否是一种明智的实现方式?或者是否有一种标准的方法是 better/easier(我是 Sharepoint 的新手,因此我不知道什么是 "normal")。

我认为有很多方法可以动态更改 Web 部件的内容。在单个 VisualWebPart 中实现此目的的一种方法是让多个控件部分分别由一个面板控件封装。使用代码控制面板的可见性以创建动态渲染。

  <asp:Panel id="DefaultPanel" runat="server" Visible="True">
  <h3>Default Text or controls here</h3></asp:Panel> 

    <asp:Panel id="SpecialPanel" runat="server" Visible="false">
<h3>Special Text or controls</h3></asp:Panel>

然后在代码中

bool showSpecialTextOnly = (someBooleanTestCondition);
if (showSpecialTextOnly )
{
   DefaultPanel.Visible=false;
   SpecialPanel.Visible=true;
}