如果我正确地回答了您的问题,则无需在数据库中存储标签或任何内容。只是您想要加载的控件的名称和路径(记住用户控件只能从同一个项目加载)。这是动态加载用户控件的代码示例。
<asp:DropDownList ID="userControlSelection" runat="server" AutoPostBack="true"
onselectedindexchanged="userControlSelection_SelectedIndexChanged">
<asp:ListItem Value="1">User Control One</asp:ListItem>
<asp:ListItem Value="2">User Control Two</asp:ListItem>
</asp:DropDownList>
<asp:Panel ID="controlHolder" runat="server" ></asp:Panel>
在代码中,重要的部分是“this.LoadControl("~/WebUserControl2.ascx");” 查看这篇文章了解更多信息并加载用户控件动态创建用户控件
protected void userControlSelection_SelectedIndexChanged(object sender, EventArgs e)
{
Control c = null;
if (userControlSelection.SelectedValue == "1")
{
c = this.LoadControl("~/WebUserControl1.ascx");
}
else if (userControlSelection.SelectedValue == "2")
{
c = this.LoadControl("~/WebUserControl2.ascx");
}
if (c != null)
{
controlHolder.Controls.Clear();
controlHolder.Controls.Add(c);
}
else
{
//Throw some error
}
}
希望这会有所帮助,谢谢