C#中控件的动态加载 以实例让大家更容易理解控件的动态加载
导航中 三个链接:查看借阅信息(NavigateUrl="ListContent.aspx?type=1") 对应的控件 1.ascx
历史借阅信息(NavigateUrl="ListContent.aspx?type=2") 对应的控件 2.ascx
预约信息(NavigateUrl="ListContent.aspx?type=3") 对应的控件 3.ascx
在ContentList.aspx里面
新建一个PlaceHolder控件 用于存放三个不同的控件
protected System.Web.UI.WebControls.PlaceHolder pcontainer;
public MyClass obj = null;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(Session["UserID"].ToString()=="")
{
Response.Redirect("Login.aspx");
}
int type = Convert.ToInt32(Request["type"]);
System.Web.UI.Control obj = null;
switch(type)
{
case 1:
obj = Page.LoadC