我的项目目前通过后面的代码将用户控件添加到 Web 表单中,例如
For Each p In userlist
Dim uc1 As New TimeSelector
panel.Controls.Add(New LiteralControl("<asp:panel1 runat=" & "server" & ">"))
panel.Controls.Add(New LiteralControl(p.ToString))
panel.Controls.Add(New LiteralControl("<asp:Updatepanel1 runat=" & "server" & ">"))
uc1 = DirectCast(Page.LoadControl("~/UserControls/StaffScheduling/TimeSelector.ascx"), UserControl)
uc1.ID = "UC" & j
panel.Controls.Add(uc1)
panel.Controls.Add(New LiteralControl("</asp:Updatepanel1>"))
panel.Controls.Add(New LiteralControl("</asp:panel1>"))
panel.Controls.Add(New LiteralControl("<p></p>"))
j += 1
Next
除了隐藏代码之外,还有更好的方法将用户控件添加到 Web 表单吗?我是否采取了最好的方法?
问候