Pass parameters to the code behind.

  • Thread starter Thread starter Mr. X.
  • Start date Start date
M

Mr. X.

Hello.

In Visual Studio 2008,
there is on the toolbox -> login -> login,
which create a login form.

On that form there is a LoginButton, which click on it is evented on the
"default.aspx.vb" codeBehind.

How can I use the value on the codeBehind (default.aspx.vb) of UserName &
Password that are on "default.aspx" ?

Thanks :)
 
The "code behind" cannot use the UserName nor the Password as it.
Maybe via request.something ?

Here is the code (that automatically generated by VS 2008) :
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Login.aspx.vb"
Inherits="CSMManager._Default" %>

<!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>

<style type="text/css">

#Text1

{

width: 248px;

margin-right: 31px;

}

#Text2

{

width: 247px;

margin-right: 31px;

}

</style>

</head>

<body>

<form id="form1" runat="server">

<asp:Login ID="Login1" runat="server" Width="395px">

<LayoutTemplate>

<table align="right" border="0" cellpadding="1" cellspacing="0" dir="rtl"

style="border-collapse:collapse;">

<tr>

<td>

<table border="0" cellpadding="0">

<tr>

<td align="center" colspan="2">

Connect~</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="UserNameLabel" runat="server"
AssociatedControlID="UserName">User Name:</asp:Label>

</td>

<td>

<asp:TextBox ID="UserName" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="UserNameRequired" runat="server"

ControlToValidate="UserName" ErrorMessage="User Name is required."

ToolTip="User Name is required."
ValidationGroup="Login1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="PasswordLabel" runat="server"
AssociatedControlID="Password">Password:</asp:Label>

</td>

<td>

<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="PasswordRequired" runat="server"

ControlToValidate="Password" ErrorMessage="Password is required."

ToolTip="Password is required."
ValidationGroup="Login1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td colspan="2">

<asp:CheckBox ID="RememberMe" runat="server"

Text="remember password" />

</td>

</tr>

<tr>

<td align="center" colspan="2" style="color:Red;">

<asp:Literal ID="FailureText" runat="server"
EnableViewState="False"></asp:Literal>

</td>

</tr>

<tr>

<td align="right" colspan="2">

<asp:Button ID="LoginButton" runat="server" CommandName="Login"

onclick="LoginButton_Click" Text="Connect" ValidationGroup="Login1"

style="height: 26px" />

</td>

</tr>

</table>

</td>

</tr>

</table>

</LayoutTemplate>

</asp:Login>

</form>

</body>

</html>



In CodeBehind : "Login.aspx.vb"

==========================

Imports System.Data.OleDb

Partial Public Class _Default

Inherits System.Web.UI.Page

Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As
EventArgs)

Dim s As String

MsgBox(UserName.text)

....

End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Load

End Sub



End Class



What should I put instead of the line MsgBox(UserName.text) ?

Thanks :)
 
Yes, that works.

I don't understand why cannot I use
UserName (It has an ID),
but I should Use Login1.UserName ?

Thanks :)
 
Back
Top