日期:2014-05-18  浏览次数:20401 次

asp.net动态加载ascx?
我做一个树型导航菜单。
我想实现:
1。单击一个树型菜单选项,加载相应的ascx
2。实现ascx动态刷新。例如每一分钟刷新一次。
请指教

------解决方案--------------------
timer 控件,定时刷新
------解决方案--------------------
刷新可以js实现,网上很多的
不过动态加载ascx,没有试过;不过你可以简单的Demo做一下就知道了阿
------解决方案--------------------
~动态加ascx~
// .aspx
例如:定义一个 <div id= "test " runat= "server ">
// .aspx.cs
Control uc = Page.LoadControl( "你的.ascx路径 ");
test.Controls.Add(uc);
这时就可以显示控件uc的内容.其中要调用的控件要注册到本页面
《详细》
private CreateContorlUI SingleUIControl;//声明用户控件

private void ControlAdd()
{
SingleUIControl = (CreateContorlUI)Page.LoadControl( "CreateSingleUI.ascx ");//加载用户控件,这里用户控件和页面在同一个目录
SingleUIControl.ID = "SingelUI ";//设置用户控件ID

this.PlaceHolderSingle.Controls.Add(SingleUIControl);//添加用户控件到页面
}
------解决方案--------------------
单击一个树型菜单选项,加载相应的ascx

if (Session[ "AdminLogin "] != null)
{
MAdminLogin user = (MAdminLogin)Session[ "AdminLogin "];
string strQuanXian = user.sType ;
if (strQuanXian == "3 ")
{
Control c1 = LoadControl( "/UserControls/cLeftNews.ascx ");

Page.Controls.Add(c1);
this.Panel1.Controls.Add(c1);

}
else
{
Control c1 = LoadControl( "/UserControls/cLeft.ascx ");

Page.Controls.Add(c1);
this.Panel1.Controls.Add(c1);

}



}