Empty Stack error when adding form tag to an ASP.N

2019-05-20 06:53发布

问题:

Ok, so, I am coming from the world of ASP programming - ASP.NET is somewhat new, and I am using Visual Studio 2013.

So, I am getting this error message when I am simply just just trying to build a simple form:

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

What in the world does all that mean?

The page seems to break when I put a <form> tag around this:

    <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>

But when I remove the form tag and "run" it, I don't that long stack error. I haven't even done anything with the *.aspx.cs file yet; there's no function calls being made, nothing.

So what in the world does this all mean? I'm really lost. Thank you.

回答1:

In ASP.Net, unless you're careful to specify an MVC site without WebForms, there is One True FormTM. You don't add your own form tags to the page. You process events created from postbacks using that one form that Visual Studio helpfully puts into the page for you.



回答2:

I had a asp:Panel with property DefaultButton="someButtonID" defined. but the someButtonID didnt exist!

I just removed DefaultButton="someButtonID".



回答3:

In asp.net you should never use a form tag yourself. all pages are wrapped in a form tag