2012-04-16 116 views
0

所以我最近一直在试图查看我一直在通过iis7工作的网站时获得这个httpexeption。下面的错误是:如何正确处理/调试HttpExceptions?

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.AddAt(Int32 index, Control child) +8689794 Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +132

[HttpException (0x80004005): Please, see whether wrapping the code block, generating the exception, within RadCodeBlock resolves the error.] Telerik.Web.UI.RadAjaxControl.MoveUpdatePanel(Control initiator, Control updated) +180
Telerik.Web.UI.RadAjaxControl.PerformRender() +375
Telerik.Web.UI.RadAjaxControl.OnPageRender(HtmlTextWriter writer, Control page) +1222
Telerik.Web.UI.RadAjaxControl.RenderPageInAjaxMode(HtmlTextWriter writer, Control page) +95
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Adapters.ControlAdapter.Render(HtmlTextWriter writer) +21 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +8703529
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266

在做对这个问题的研究,唯一可行的解​​决方案,我有似乎发现了包裹的javascript radcodeblock内或使用<span runat="server">。我已经尝试了这两种方法,似乎都没有工作。我也有点困惑,为什么我会得到这个错误,因为没有任何由本网站以前的开发人员实施的JavaScript包含任何项目,据我所知,使用<%...%>

此外,我已经提前检查并检查了页面中的所有控件,以确保其抱怨的上述情况实际上并未发生。换句话说,据我所知,在代码中没有任何地方使用<%...%>,而不是在页面的声明中。即:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginPage.aspx.cs" Inherits="Datamart.UI.Reporting.Web.LoginPage" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" ValidateRequest="False" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 

所以我想知道它是什么我可能是做错了还是什么将是找出哪里和我的究竟是什么问题的下一个步骤。当我认为是存在的位于下面的错误:

<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server"> 
      <script type="text/javascript"> 
      function onTabSelecting(sender, args) 
      { 
       if (args.get_tab().get_pageView()) 
       { 
        if (args.get_tab().get_pageView().get_id()) 
        { 
         args.get_tab().set_postBack(false); 
        } 
       } 
      } 
      function StopPropagation(e) 
      { 
       //cancel bubbling 
       e.cancelBubble = true; 
       if (e.stopPropagation) 
        e.stopPropagation(); 
      } 

      //the following code use radconfirm to mimic the blocking of the execution thread. 
      //The approach has the following limitations: 
      //1. It works inly for elements that have *click* method, e.g. links and buttons 
      //2. It cannot be used in if(!confirm) checks 
      window.blockConfirm = function(text, mozEvent, oWidth, oHeight, callerObj1, oTitle) 
      { 
       var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually 
       //Cancel the event 
       ev.cancelBubble = true; 
       ev.returnValue = false; 
       if (ev.stopPropagation) 
        ev.stopPropagation(); 
       if (ev.preventDefault) 
        ev.preventDefault(); 

       //Determine who is the caller 
       var callerObj = ev.srcElement ? ev.srcElement : ev.target; 

       //Call the original radconfirm and pass it all necessary parameters 
       if (callerObj) 
       { 
        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again. 
        var callBackFn = function(arg) 
        { 
         if (arg) 
         { 
          callerObj["onclick"] = ""; 
          if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz 
          else if (callerObj.tagName == "A") //We assume it is a link button! 
          { 
           try 
           { 
            eval(callerObj.href) 
           } 
           catch (e) { } 
          } 
         } 
        } 

        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle); 
       } 
       return false; 
      } 
      function noBack() 
      { 
       window.history.forward(); 
      } 
      noBack(); 
      window.onload = noBack; 
      window.onpageshow = function(evt) 
      { 
       if (evt.persisted) noBack(); 
      } 
      window.onunload = function() 
      { 
       void (0); 
      } 
      </script>   
     </telerik:RadScriptBlock> 

这在我的页面的正文中,但我已经尝试过移动到页面的底部,以及在头部,因为被发现成为其他人可能的解决方案,但无济于事。

任何帮助或建议,非常感谢。谢谢。

回答

0

听起来像是由于错误,某个地方的代码想要动态地将控件添加到页面,并且正在添加的控件具有动态内容。我会寻找类似

Controls.Add(

的代码然后看看是否注释掉该行。这也可能是Telerik软件中的一个错误,因此您可以尝试在他们的论坛上张贴或通过电子邮件发送他们的支持,以查看这个问题是否已经出现。