以Web表单输入数据,输出到新页面

时间:2014-04-22 12:58:26

标签: c# html asp.net web

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

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

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

我使用ASP.NET编写C#。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

看到您正在使用ASP.Net,我建议您利用代码隐藏过程的强大功能。除了以上回复之外,您可以执行的一个选项是在QueryString中使用URL进行重定向,如果您可以将其作为要求使用。

示例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中 - 这只是一个带有一堆setter和{{{ 1}}Š
在ASP按钮上执行click事件,除了这次你会做这样的事情:

getter