Asp.net 将值从 txtbox 传递到另一个页面

Fra*_*arp 2 vb.net asp.net

这是我的代码的结尾

 ...
 If lblErrMsg.Text = "" Then

     Response.Redirect("UserPage.aspx")
    End If
Run Code Online (Sandbox Code Playgroud)

我想将 txtUser 的值(我在当前页面中创建它...)传递给 UserPage.aspx。

谢谢你帮我...

这是在 VB.net 中而不是在 c# 中,请

Shy*_*yju 5

C#版本

1)使用查询字符串

Response.Redirect("user.aspx?val="+txtBox.Text);
Run Code Online (Sandbox Code Playgroud)

在 userp.aspx.cs 中,

string strVal=Request.QueryString["val"];
Run Code Online (Sandbox Code Playgroud)

2)使用会话

重定向前在首页设置会话

Session["val]=txtBox.Text;
Response.Redirect("user.aspx");
Run Code Online (Sandbox Code Playgroud)

并在 user.aspx.cs 中

  String strVal=(string) Session["val"];
Run Code Online (Sandbox Code Playgroud)

编辑:VB.NET版本

1) 使用查询字符串

Response.Redirect("user.aspx?val=" + txtBox.Text)
Run Code Online (Sandbox Code Playgroud)

并在 user.aspx.vb 中

Dim strVal As String = Request.QueryString("val")
Run Code Online (Sandbox Code Playgroud)

2)使用会话

在首页设置会话

Session("val")=txtBox.Text
Response.Redirect("user.aspx")
Run Code Online (Sandbox Code Playgroud)

以及 user.aspx.vb 中。

Dim strVal As String = DirectCast(Session("val"), String)
Run Code Online (Sandbox Code Playgroud)