Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以web表单输入数据,输出到新页面_C#_Html_Asp.net_Web - Fatal编程技术网

C# 以web表单输入数据,输出到新页面

C# 以web表单输入数据,输出到新页面,c#,html,asp.net,web,C#,Html,Asp.net,Web,我正在使用一个简单的从用户那里收集数据。用户单击一个简单的按钮输入数据:。当前,应用程序执行简单的回发操作,显示已填写的表单,并在表单下显示结果 用户现在希望结果转到另一个页面。基本上,他们希望更改一个变量,并在不同的选项卡中比较结果。我的第一个建议是保留帖子,然后使用target=“\u blank”添加一个超链接,将结果推到另一个选项卡上,但他们不喜欢两次单击:确定按钮,然后是超链接 是否可以将表单输入的结果发送到另一个页面 我使用ASP.NET在C#中编程。您可以通过C#中的postbac

我正在使用一个简单的
从用户那里收集数据。用户单击一个简单的按钮输入数据:
。当前,应用程序执行简单的回发操作,显示已填写的表单,并在表单下显示结果

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

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


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

您可以通过C#中的postbackurl属性来完成此操作。这样可以帮助您访问上一页控件,并在下一页显示输出。您也可以通过使用隐藏字段和post或get方法来实现这一点。这两种选择都是好的和可靠的。
鉴于您正在使用ASP.Net,我建议您利用代码隐藏过程的强大功能。除了上述回答之外,您还可以选择在您的
URL
中使用
QueryString
,如果您需要的话,也可以使用re direct

示例1。使用ASP
按钮

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。使用
会话
变量并将数据集/结果存储在用户定义的对象或
DTO
-这只是一个包含大量
setter
s和
getter
s的类
在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;
    }

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