1,html page
Head registration:
<%@ Register SRC="~/worklog/worklognewv1/usercontrol/ceshibu.ascx"TagPrefix="UserControl"TagName="Ceshibu"%><%@ Register SRC="~/worklog/worklognewv1/usercontrol/kaifabu.ascx"TagPrefix="UserControl"TagName="Kaifabu"%>
Control Placement:
<id= "Controlspan" runat=server> </ div>
2,c# Backstage
/// <summary> ///determine which features in a user control are displayed based on items and classifications/// </summary> /// <param name= "STRFL" ></param> /// <param name= "STRSX" ></param> Private voidSetusercontrolvisible (stringSTRFL,stringSTRSX) { if(viewstate["Rzdeptname"]. ToString () = ="Development Department") {
User Control path UserControl kaifabucontrol= (UserControl) Page.LoadControl ("Usercontrol/kaifabu.ascx"); Type TC=Kaifabucontrol.gettype ();
The initialization method to invoke in the user control System.Reflection.MethodInfo m= TC. GetMethod ("OnStart");
Calling the parameters to be passed by the initialization methodObject[] Bjparas =New Object[1]; bjparas[0] =STRSX; M.invoke (Kaifabucontrol, Bjparas); Controlspan. Controls.clear (); Controlspan. Controls.Add (Kaifabucontrol); } if(viewstate["Rzdeptname"]. ToString () = ="Testing Department") {UserControl Kaifabucontrol= (UserControl) Page.LoadControl ("Usercontrol/ceshibu.ascx"); Type TC=Kaifabucontrol.gettype (); System.Reflection.MethodInfo m= TC. GetMethod ("OnStart"); Object[] Bjparas =New Object[1]; bjparas[0] =STRSX; M.invoke (Kaifabucontrol, Bjparas); Controlspan. Controls.clear (); Controlspan. Controls.Add (Kaifabucontrol); } }
Dynamically changing STRFL,STRSX on a page can dynamically load different user controls or load different elements in a user control.