xuanvu
  •  xuanvu
  • 78.8% (Friendly)
  • YAF Forumling Topic Starter
2009-03-18T09:36:14Z
Hi all,
All of a sudden, I receive this error when clicking on "Inbox" after logged in. I don't remember seeing this error before when accessing the Inbox, and there were no changes at all to the forum code.



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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
   System.Web.UI.ControlCollection.Add(Control child) +8677431
   AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) +871
   AjaxControlToolkit.ScriptControlBase.OnLoad(EventArgs e) +59
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


Thanks,
Kenny.
Sponsor
mddubs
2009-03-18T10:25:11Z
"All of a sudden" ... that's my favorite expression :)

You sure? I don't see any YAF controls in that stack trace... did you change the Ajax dll?
UserPostedImage 
www.bunkerhollow.com  | www.careercomputing.com 
When I post fp:mddubs in a topic, I'm leaving my footprint there so I can track it once I get into coding/supporting. (Yes I stole this off Mek 🙂, who stole this off Ederon 🙂 )
xuanvu
  •  xuanvu
  • 78.8% (Friendly)
  • YAF Forumling Topic Starter
2009-03-18T13:52:08Z
Okay so I found out the code that causes the problem. If I have this code (this code is in the Masterpage), the erorr shows up, if I comment them out, the forum run just fine.


<!-- Mudim VietTyping JS, version 0.8 r153 -->
    <script type="text/javascript" src='<%=ResolveClientUrl("~/Includes/mudim.js") %>'></script>
    
    <!-- Begins TinyMCE Config Section -->

    <script type="text/javascript" src='<%=ResolveClientUrl("~/Includes/tinymce/tiny_mce_gzip.js") %>'></script>


What should I do to call these 2 scripts and still have the forum function as it should?

Thanks,
Kenny.
xuanvu
  •  xuanvu
  • 78.8% (Friendly)
  • YAF Forumling Topic Starter
2009-03-18T14:08:12Z
Well I found the solution, in case someone else run into the same problem, here is what I do:

Change

    <script type="text/javascript" src='<%=ResolveClientUrl("~/Includes/mudim.js") %>'></script>


to


    <script type="text/javascript" src='<%#ResolveClientUrl("~/Includes/mudim.js") %>'></script>


Then override the OnLoad method:

protected override void OnLoad(EventArgs e)
	{
		base.OnLoad(e);
		Page.Header.DataBind();
	}


That should do it.

Kenny.
bdaly
  •  bdaly
  • 50.6% (Neutral)
  • YAF Forumling
2010-06-14T05:55:15Z
This is very late but since the problem still exists in VS 2010 and I spent a lot of time finding it, here's another (possibly easier) solution in case someone needs it. You may also run into this if when linking to a CSS page.

ASP.NET won't let you use <% %> tags directly in the <HEAD> tag of a Master Page. Also, you can't use "~/" as a path in anything except a server control (e.g. has runat="server" attribute.) So what's a programmer to do?

Wrap the script tag in a ContentPlaceHolder control. That way it's not directly in the HEAD tag, it's in ContentPlaceHolder in the HEAD tag. Yes this is ridiculous and MS should fix it, but this solution works for now.

<asp:ContentPlaceHolder ID="NeededToMakeServerPathsWorkInHeadTag" runat="server">
<script type="text/javascript" src='<%=ResolveClientUrl("~/Includes/mudim.js" ) %>'></script>
</asp:ContentPlaceHolder>

I believe you'll have the same problem in server controls if the page hosting the control has <% %> tags in the <HEAD>. The solution is the same.

I hope someone else runs into this problem, they find this useful. I could have used it hours ago.

About Us

The YAF.NET is an open source .NET forum project. YAF.NET is supported by an team of international developers who are build community by building community software.

Powered by Resharper Donate with PayPal button

Project Twitter Updates

Copyright © YetAnotherForum.NET & Ingo Herbote. All rights reserved