在一个Menu_AboutUs.ascx中有这样一段:
<!-- #include file="MenuLeft.ascx" -->
....
 <table width="88"  border="0" align="center" cellpadding="0" cellspacing="0" background="<%=BackgroundImage%>">
....
而MenuLeft.ascx文件中有一段:
private string _backgroundImage="~/indexC/leftSubButtonBg.gif";
public string BackgroundImage
{
  get { return _backgroundImage; }
  set { _backgroundImage = value; }
}以上用法能正常使用。但如果将Menu_AboutUs.ascx中<!-- #include file="MenuLeft.ascx" -->改为:
<%@ Register TagPrefix="MyMenu" TagName="MenuLeft" Src="MenuLeft.ascx" %>
  <form runat="server">
    <MyMenu:MenuLeft runat="server" />
....
 <table width="88"  border="0" align="center" cellpadding="0" cellspacing="0" background="<%=BackgroundImage%>">
....
  </form>
时就报错?
(问题就在这里:<%=BackgroundImage%>)应该如何解决类似这种ascx中包含ascx的问题?
include的加载期是在什么位置?

解决方案 »

  1.   

    因为用Register的方式和用include 的方式,页面加载的顺序是不一样的,
    inlcude 方式, 先加载.ascx文件,然后执行.aspx文件,
    Register方式,先执行.aspx的page_load,然后加载.ascx文件,因为你的:<%=BackgroundImage%>是在.aspx的page_load里面赋值的,而这个时候,.ascx还没有加载进来,当然要出错了。你看下下面这篇文章
    http://www.cnblogs.com/dannyr/archive/2004/10/13/51530.aspx
      

  2.   

    未解决实质性问题,当include涉及运行时嵌套,如何采用嵌套的ascx来解决呢?
    UP
      

  3.   

    <%#BackgroundImage%>
    page_load(...)
    {
    BackgroundImage = "sdfsdf";
    DataBind();
    }
      

  4.   

    lcy5415(沈阳.NET) :
    如何动态加载?