c# - 如何将一组字符串从一个 ASP.NET 页面发送到另一个页面?

标签 c# asp.net linker

我现在有两个 asp.net 页面。当我单击页面 A 上的链接时,我会打开另一个链接(我们称之为页面 B)。当我这样做时,我想以字符串数组的形式将一些信息从页面 A 发送到页面 B。该数组根据我在页面 A 上点击的链接而有所不同。

我知道我可以通过带有 ?string1=bla1&string2=bla2 等的 URL 发送此信息,但我不希望这样,因为如果数组中的字符串太多,它会变得复杂。

我认为有类似的东西,比如 PHP 中的 POST,但在 ASP 中会怎样呢?

如有任何帮助,我们将不胜感激。谢谢。

干杯!

最佳答案

您可以只使用 session 状态。你会像这样在第一页中填充它

Page.Session["MyArray"] = new string[] {"one", "two", "three" };

然后使用如下内容检索目标页面中的信息:

string[] values = Page.Session["MyArray"] as string[];

编辑:

为了回应您的评论,您需要处理链接按钮的 OnClick 事件,例如

<asp:LinkButton ID="myButton" Text="Click Me" OnClick="myButton_Click" runat="server"/>

然后在后面的代码中,您需要像上面那样设置 session 状态,例如

protected void myButton_Click(object sender, EventArgs e)
{
    Page.Session["MyArray"] = new string[] {"one", "two", "three" };
    Response.Redirect("~/AnotherPage.aspx");
}

关于c# - 如何将一组字符串从一个 ASP.NET 页面发送到另一个页面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2948805/

相关文章:

c# - 在 datagridview 中更新日期格式时出现错误

c# - 一个参数或多个

javascript - 如何使用 "next"按钮选择 Bootstrap 选项卡。我遵循了其他答案但没有工作

c# - 获取客户端的操作系统名称

c# - 更改 gridview 内下拉菜单的日期格式

linker - 在 Linux 上使用 GNU makefile 链接 protobuf 库

c# - 如何将一个 ViewModel 转换为另一个 ViewModel?

c# - 如何让ffmpeg.exe解决输入帧序列的fps不一致问题?

c++ - 链接器错误 : undefined reference to function from header file

c++ - 为什么隐藏符号仍然添加到 DSO