【问题标题】:Enter data in web form, output to a new page以网页形式输入数据,输出到新页面
【发布时间】:2014-04-22 12:58:25
【问题描述】:

我正在使用简单的<form> 从用户那里收集数据。用户单击一个简单的按钮来输入数据:<input type="submit" name="cmd" value="OK">。目前,该应用程序执行简单的回发,显示填写的表单,并在表单下方显示结果。

用户现在希望将结果转到另一个页面。基本上,他们想要更改变量并比较不同选项卡中的结果。我的第一个建议是保留帖子,然后使用target="_blank" 添加超链接以将结果推送到不同的选项卡,但他们不喜欢单击两次:确定按钮然后超链接。

是否可以将表单输入的结果发送到另一个页面?

我正在使用 ASP.NET 在 C# 中编程。

【问题讨论】:

  • 你应该把两个数据都存起来比较,这样会更专业。您可以通过多种不同的方式存储数据:cookie、会话、静态数据、写入文本文件、保存到数据库等。存储后,您可以在一个好看的页面中呈现比较。

标签: c# html asp.net web


【解决方案1】:

您可以通过 c# 中的 postbackurl 属性来执行此操作。因此可以帮助您访问上一页控件并在下一页上输出。您也可以通过使用隐藏字段和 post 或 get 方法来做到这一点。两种选择都很好且可靠。 reference

【讨论】:

    【解决方案2】:

    鉴于您使用的是 ASP.Net,我建议您利用代码隐藏过程的强大功能。除了上述响应之外,您可以做的一个选择是在您的URL 中使用QueryString,因为您可以根据需要进行重定向。

    示例 1. 使用 ASP Button

    protected void btnOriginalPage_Click(object sender, EventArgs e)
    {
        string url = "NextPageViewer.aspx?result=" + resultText;
    
        //You can use JavaScript to perform the re-direct
        string cmd = "window.open('" + url + "', '_blank', 'height=500,width=900);";
        ScriptManager.RegisterStartupScript(this, this.GetType(), "newWindow", cmd, true);
    
        //or you can use this - which ever you choose
        Response.Redirect(url);
    }
    
    ///On the next page - the one you have been redirected to, perform the following
    protected void Page_Load(object sender, EventArgs e)
    {
        //extract the query string and use it as you please
        int result = Convert.ToInt32(Request.QueryString["resultText"]);
    }
    

    示例 2. 使用 Session 变量并将数据集/结果存储在用户定义的对象或 DTO - 这只是一个包含 setters 和 getters 的类
    在 ASP 按钮上执行单击事件,但这次您将执行以下操作:

    protected void btnOriginalPage_Click(object sender, EventArgs e)
    {
        ObjectWithInfo.Result = result;
    
        Session["friendlyName"] = ObjectWithInfo;
    
        Response.Redirect("NextPageViewer.aspx");
    }
    
        //On the next page - the one you have been redirected to, perform the following
    //The good thing with Session variables is that you can access the session almost anywhere in you application allowing your users to perform the comparison they require.
        protected void Page_Load(object sender, EventArgs e)
        {
            //extract the data from the object to use
            int result = ((ObjectWithInfo)(Session["friendlyName"])).Result;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-30
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 2017-02-27
      • 2017-08-10
      • 2013-06-06
      • 1970-01-01
      相关资源
      最近更新 更多