mishrsud / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

MiniProfiler Conflict with asp.net Menu Control #116

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In setting up the MiniProfiler for my WebForm site, I ran into the following 
error when loading my page (master page + content page):

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

The MiniProfiler was set up as indicated in the webform samples on the mini 
profiler site.   

Upon further testing, I found the error happened when I included a menu control 
(with at least one menu item) in the body of the master page.   The following 
will produce the error above:

...
<head runat="server">
    <title>Test Master Page</title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>

     <%= MvcMiniProfiler.MiniProfiler.RenderIncludes() %> 
</head>
<body>
    <form id="form1" runat="server">
    <h1>Master Page</h1>

    <asp:Menu ID="Menu1" runat="server">
        <Items>
            <asp:MenuItem Text="New Item" Value="New Item"></asp:MenuItem>
        </Items>
    </asp:Menu>

...

I found that if I moved the RenderIncludes() anywhere in the body section, the 
error would go away.   

This doesn't appear to affect the profile results, so I'm fine with doing this, 
but I thought I would report this.   

Original issue reported on code.google.com by brnv...@gmail.com on 12 Oct 2011 at 2:14

GoogleCodeExporter commented 8 years ago
In the applications that are using Mini Profiler we alter the controls with in 
the head tag and this results in the error you have.

What I have done (this has been working for my applications in production no 
problem) is wrap the call in a placeholder control.

<asp:PlaceHolder runat="server">
    <%= MvcMiniProfiler.MiniProfiler.RenderIncludes() %> 
</asp:PlaceHolder>

My understanding is that the method RenderIncludes() outputs HTML to the page 
and does not alter the control collection. As soon as the controls within the 
head tag are altered it throws an error because the html renders is not part of 
a control. Wrapping it in a control solves this issue. 

I am not sure what the menu control is doing that it is altering the head 
control but I am sure if you check what it renders you will find something that 
is altered in the head tag.

Hope this helps

Original comment by MHB...@gmail.com on 10 Jan 2012 at 9:51

GoogleCodeExporter commented 8 years ago
You can also change 
<%= MvcMiniProfiler.MiniProfiler.RenderIncludes() %> 
to be
<%# MvcMiniProfiler.MiniProfiler.RenderIncludes() %> 

and then in Site.Master.cs make a call to Page.Header.DataBind() like so:

protected void Page_Load(object sender, EventArgs e)
{
   Page.Header.DataBind();
}

Original comment by admi...@gmail.com on 19 Mar 2012 at 10:12

GoogleCodeExporter commented 8 years ago
The current best practice with MiniProfiler 2.0 is to do the render includes 
"just before" closing the <BODY> tag 

Original comment by sam.saff...@gmail.com on 3 Apr 2012 at 4:25