【问题标题】:Empty Stack error when adding form tag to an ASP.Net Webforms page将表单标记添加到 ASP.Net Webforms 页面时出现空堆栈错误
【发布时间】:2014-08-13 23:40:51
【问题描述】:

好的,所以,我来自 ASP 编程世界 - ASP.NET 有点新,我使用的是 Visual Studio 2013。

所以,当我只是想构建一个简单的表单时,我会收到此错误消息:

Server Error in '/' Application.

Stack empty.

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.InvalidOperationException: Stack empty.

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: 


[InvalidOperationException: Stack empty.]
   System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) +52
   System.Collections.Generic.Stack`1.Pop() +6694385
   Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.EndRendering(TextWriter writer, Object renderedObject) +85
   System.Web.UI.RenderTraceListenerList.EndRendering(TextWriter writer, Object renderedObject) +58
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +142
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

这到底意味着什么?

当我在其周围放置<form> 标签时,页面似乎中断了:

    <form id="form1" runat="server">

<asp:TextBox ID="post_feedback" runat="server" Height="100" Width="500" BackColor="#0066FF" Font-Bold="True" ForeColor="#FF9933" Wrap="False" TextMode="MultiLine" BorderColor="#000099" BorderStyle="Groove" BorderWidth="2"></asp:TextBox>  

</form>

但是当我删除表单标签并“运行”它时,我没有那么长的堆栈错误。我什至还没有对 *.aspx.cs 文件做任何事情;没有进行函数调用,什么都没有。

那么这一切到底意味着什么?我真的迷路了。谢谢。

【问题讨论】:

  • (标题的选择确实会影响问题的接受度。)
  • 您确定form标签中的属性runat有效吗?
  • 很多反对将其搁置的人应该考虑先自己进行编辑。

标签: c# asp.net visual-studio webforms


【解决方案1】:

请多次检查是否有asp:DropDownList asp:ListItem Selected="True"。

<asp:DropDownList ID="ddlTest"   runat="server">     
    <asp:ListItem Text="Text1" Selected="True" Value="1"></asp:ListItem>
    <asp:ListItem Text="Text2" Value="2"></asp:ListItem>     
    <asp:ListItem Text="Text3" Value="3"></asp:ListItem>
    <asp:ListItem Text="Text4" Value="4"></asp:ListItem>
    <asp:ListItem Text="Text5" Selected="True" Value="5"></asp:ListItem>    
</asp:DropDownList>

【讨论】:

    【解决方案2】:

    我有一个 asp:Panel,其中定义了属性 DefaultButton="someButtonID"。但 someButtonID 不存在!

    我刚刚删除了 DefaultButton="someButtonID"

    【讨论】:

    • 与 asp:Label 相同,它的 AssociatedControlID 错误。纠正它解决了问题
    【解决方案3】:

    在 asp.net 中,您永远不应该自己使用 form 标记。所有页面都包含在一个表单标签中

    【讨论】:

    • 嗨,彼得 - 我要引用我在书中看到的一个例子。在该示例中,明确使用了
      标记。 (Murach 的 ASP.NET 4.5 Web Programming with C3)感谢评论/帮助。 :)
    • HighCore - 拖钓没有帮助。 寻找忽略按钮
    【解决方案4】:

    在 ASP.Net 中,除非您仔细指定没有 WebForms 的 MVC 站点,否则只有一个 True FormTM。您不会将自己的表单标签添加到页面中。您可以使用 Visual Studio 帮助您放入页面的一种表单来处理从回发创建的事件。

    【讨论】:

      猜你喜欢
      • 2021-03-28
      • 2018-10-10
      • 2019-03-20
      • 1970-01-01
      • 2010-11-14
      • 2012-12-11
      • 2011-09-06
      • 2014-01-29
      • 1970-01-01
      相关资源
      最近更新 更多