如何将文本框的值传递到asp.net中的另一个页面(vb)

时间:2016-02-10 05:23:10

标签: html asp.net vb.net

<form method = "post" action = "" runat="server">
                <p><asp:TextBox id="txtUser" runat="server" placeholder="Username"/></p>
                <p><asp:TextBox id="txtPass" runat="server" TextMode="Password" placeholder="Password"/></p>
                   <asp:Button id="btnLogin" Text="Login" runat="server" PostBackUrl ="~/Main.aspx" />
</form>

在我的login.aspx代码中。

我想获取我在login.aspx页面中输入的用户名和密码,并将其传递给我在Main.aspx页面中声明的字符串存储。

这是我在main.aspx中的代码:

<script runat="server">
    Dim txtUsername
    Dim txtPassword

    Sub Page_Load()

    End Sub
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h3><b><asp:Label ID="lblUser" runat="server" Text="Username: "></asp:Label>
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            </b></h3>
    </div>
        <h3><b><asp:Label ID="lblPass" runat="server" Text="Password: "></asp:Label>
            <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </b></h3>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:4)

1.在源页面中,保存要在会话状态中传递的信息,如以下示例所示:

 Session("password") = "value1"//txtPass.Text
Session("username") = "value2"//txtUser.Text

2.在目标页面中,从会话状态中读取保存的信息,如以下示例所示:

 Dim password as String = CType(Session.Item("password"), String)
 Dim username as String = CType(Session.Item("username"), String)

您可以参考以下链接获取更多选项..

https://msdn.microsoft.com/en-us/library/6c3yckfw.aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2