简体   繁体   English

ASP.NET在提交表单后获取空白页面(初学者)

[英]ASP.NET Getting a blank page after submitting a form (beginner)

I am trying to make some game, I'm not going to explain what is it because it's not really important, anyway, the problem is the following form: 我正在尝试制作一些游戏,我不打算解释它是什么,因为它并不重要,无论如何,问题是以下形式:

http://pastebin.com/8XwdDFWY http://pastebin.com/8XwdDFWY

after submitting that form I'm getting a blank page. 提交该表格后,我得到一个空白页面。

Here's the server side code which that form navigates to: 这是表单导航到的服务器端代码:

http://pastebin.com/tfeAMxrF http://pastebin.com/tfeAMxrF

Thank for helpers! 谢谢佣工!

To backup Aristos answer IsPostBack only works when you submit to the same page. 备份Aristos答案IsPostBack仅在您提交到同一页面时有效。 You are cross page scripting therefore it's not a postback but a new request. 您是跨页面脚本,因此它不是回发而是新请求。

  • Use a single aspx page to handle the form and result (don't change the form action) 使用单个aspx页面来处理表单和结果(不要更改表单操作)
  • Put the code in your code behind file 将代码放在代码后面的文件中
  • Use a Literal or Label control to display the result 使用Literal或Label控件显示结果

The issue is that you use the IsPostBack that is stop from showing the data after the post back. 问题是您使用IsPostBack停止在回发后显示数据。 Ether remove it, ether use asp.net controls that "remembers *" the content after the post back. 以太网删除它,以太网使用asp.net控件在回发后“记住*”内容。

<%
    // this part is blocked as it is, after the post back
    if (Page.IsPostBack)
    {
        int n = int.Parse(Request.Params["number"]);
        string name = Request.Params["fname"];
        int points = CalcPoints(name, n);
     %>
     Hello <%=name%> You have chosen number <%=n%>
     The random numbers are : <%=num1 + " , " + num2 + " , " + num3%>
     You have scored <%=points%> points!
     <%
    }
    %>

[*] they saved into the view state [*]他们保存到视图状态

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 提交表单后在 ASP.NET MVC 中。 它不会重定向到其他页面。 它正在加载相同的页面 - In ASP.NET MVC after submitting form. it is not redirecting to other page. its loading same page 使用 HttpPost 方法提交表单后,ASP.NET Core 重定向到同一页面 - ASP.NET Core redirecting to the same page after submitting a form with HttpPost method 在 IIS 上部署 ASP.NET MVC 应用程序后出现空白页 - Getting blank page after deploying ASP.NET MVC application on IIS ASP.NET剃刀:表单未提交 - ASP.NET razor: Form not submitting Asp.net初学者 - Asp.net Beginner 在ASP.NET Core 2中提交表单,并收到错误消息“正在发送数据状态代码:404; 未找到” - Submitting a form in ASP.NET Core 2 and getting an error “Sending Data Status Code: 404; Not Found” 获取由目标页面ASP.NET上的表单发布的值 - Getting values posted by a form on target page ASP.NET 在 ASP.NET MVC 中提交表单后创建新的应用程序用户 - Create new Application User After Submitting Form in ASP.NET MVC 使用 Javascript 在 ASP.NET 核心中提交表单后生成 reCAPTCHA v3 令牌 - reCAPTCHA v3 token generation after submitting form in ASP.NET Core using Javascript 提交带有结果数据的表单后如何将返回的数据绑定到 Telerik ASP.Net Core 网格 - How to bind returned data to a Telerik ASP.Net Core grid after submitting a form with resulted data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM