ResolveUrl not working inline

前端 未结 2 1314
误落风尘
误落风尘 2021-02-20 04:49

I am getting the error on the below code in asp.net 4.0



        
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-20 05:15

    You can't use <%# and <%= at the same time. Try it like this:

    
    

    EDIT
    If you are getting an error that states:

    The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
    

    when you try to use <%= ResolveUrl(..., it is because something in your code is attempting to add controls to your header control in Site.Master. If that is the case, switch the script tag to read:

    
    

    and make sure you call the DataBind() method on the header tag at some point (for example, from the Page_Load method for Site.Master):

    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Header.DataBind();
        }
    }
    

提交回复
热议问题