桂林咚鼓dj网:如何在asp.net的web页面中包含另外一个web页面

来源:百度文库 编辑:高校问答 时间:2024/04/25 12:41:03
如何在asp.net的web页面中包含另外一个web页面
asp里面是<!--#include file="xxx"-->
那.net里面呢?
是在引用了母板页面的content里面引用其它页面

用自定义控件,把要包含进去的内容写成一个自定义控件,
然后在主页面中调用自定义控件
例:
新建一个自定义控件c_topwin.ascx
内容和编写aspx文件一样
然后在要调用的页面最上面加入:
<%@ Register TagPrefix="topwin" TagName="c_topwin" Src="/control/c_topwin.ascx" %>

TagPrefix:控件前缀
TagName:控件名
Src:控件路径

最后在要加入控件的地方加入:
<topwin:c_topwin runat="server" id="c_topwin1"/>



<topwin:c_topwin runat="server" id="c_topwin1"></topwin>

另外也可以在程序中动态加载自定义控件
可使用PlaceHolder先占位,然后用PlaceHolder1.Controls.Add(Page.LoadControl("/control/c_topwin.ascx"));

但是动态加载的自定义控件在PostBack后内容会消失,解决方法如下:
加入PlaceHolder 名为ctl_main,在页面的Page_Load方法中:
if(!IsPostBack)
{
Control ctl=Page.LoadControl("/control/c_topwin.ascx");
ctl.ID="ctl_loaded";
this.ctl_main.Controls.Add(ctl);
ViewState["ctl_loaded"]="/control/c_topwin.ascx";
}
else
{
ctl=Page.LoadControl(ViewState["ctl_loaded"].ToString());
ctl.ID="ctl_loaded";
this.ctl_main.Controls.Add(ctl);
}
在视图状态中增加一个标志位,表示是否点击了按钮来加载用户控件,当然如果已经加载了再点击按钮就不需要重复加载了。

<iframe frameborder="0" width="100%" height="100%" src=Eed.aspx id="Endfream"></iframe>
这是是上面的那个大哥你不会就别乱回答