Hi,
there, i am trying to come up with this behind code using vb. i am getting error saying 'the username and password is not declared. i am not sure how to declare. please assisst me in this. this is a button which should work in a login page.

Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        
        
        If Membership.ValidateUser(UserName.Text, Password.Text) Then
            ' Log the user into the site 
            FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked)
        End If
        ' If we reach here, the user's credentials were invalid 
        InvalidCredentialsMessage.Visible = True

    End Sub
Comments
Keep your post well-formated. Use BB code tags

Keep your post well-formated. Use BB code tags.

>the username and password is not declared..
It means you haven't place textboxes named "username" and "password". Check the ID property of TextBoxes.

sir, ive already placed the textbox and named them accordingly as below.

Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        
        
        If Membership.ValidateUser(UserName.Text, Password.Text) Then
            ' Log the user into the site 
            FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked)
        End If
        ' If we reach here, the user's credentials were invalid 
        InvalidCredentialsMessage.Visible = True

    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    
   
     
    </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>" 
        
        InsertCommand="Select_Login"
            InsertCommandType="StoredProcedure" 
        SelectCommand="SELECT UserID, Password FROM StaffRegis_Table where ((UserID=@UserID) AND (Password=@Password))">
        
        <SelectParameters>
            <asp:CookieParameter CookieName="UserID" DefaultValue="User ID" 
                Name="USerID" />
            <asp:CookieParameter CookieName="Password" DefaultValue="Password" 
                Name="Password" />
        </SelectParameters>
        
        <InsertParameters>
                
                <asp:Parameter Name="UserID" Type="String" />
                <asp:Parameter Name="password" Type="String" />
            </InsertParameters>
    
    </asp:SqlDataSource>
    <asp:Login ID="Login1" runat="server" CreateUserUrl="~/PasswordRecover.aspx" CreateUserText="Forgot your password?"
      Height="58px" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="Login1_Authenticate">
        <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <LayoutTemplate>
            <table border="0" cellpadding="1" cellspacing="0" style="border-collapse: collapse;
                height: 150px; width: 244px;">
                <tr>
                    <td>
                        <table border="0" cellpadding="0" style="height: 58px">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #6b696b">
                                    Log In</td>
                                <td align="center" colspan="1" style="font-weight: bold; color: white; background-color: #6b696b">
                                </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>
                                <td>
                                </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" Height="22px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                </td>
                                <td colspan="1">
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color: red">
                                    <br />
                                    <asp:LinkButton ID="LbTNPassword" runat="server" 
                                        PostBackUrl="~/PasswordRecover.aspx">Forgot your password?</asp:LinkButton>
                                    <br />
                                    <br />
                                    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/StaffRegis.aspx">Create 
                                    an account</asp:LinkButton>
                                    &nbsp;<br />
                                    <br />
                                </td>
                                <td align="center" colspan="1" style="color: red">
                                    &nbsp;</td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <br />
                                    <br />
                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" 
                                        ValidationGroup="Login1" PostBackUrl="~/Transactions.aspx" 
                                        onclick="LoginButton_Click" />
                                </td>
                                <td align="right" colspan="1">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:Login>

    </asp:Content>

sir, i've already attached the textboxes and named them accordingly.I am still getting the error.please help

Protected Sub LoginButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        
        
        
        If Membership.ValidateUser([B]UserName.Text, Password.Text[/B]) Then
            ' Log the user into the site 
            FormsAuthentication.RedirectFromLoginPage(UserName.Text, RememberMe.Checked)
        End If
        ' If we reach here, the user's credentials were invalid 
        InvalidCredentialsMessage.Visible = True

    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    
   
     
    </asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:CourierSystemConnectionString %>" 
        
        InsertCommand="Select_Login"
            InsertCommandType="StoredProcedure" 
        SelectCommand="SELECT UserID, Password FROM StaffRegis_Table where ((UserID=@UserID) AND (Password=@Password))">
        
        <SelectParameters>
            <asp:CookieParameter CookieName="UserID" DefaultValue="User ID" 
                Name="USerID" />
            <asp:CookieParameter CookieName="Password" DefaultValue="Password" 
                Name="Password" />
        </SelectParameters>
        
        <InsertParameters>
                
                <asp:Parameter Name="UserID" Type="String" />
                <asp:Parameter Name="password" Type="String" />
            </InsertParameters>
    
    </asp:SqlDataSource>
    <asp:Login ID="Login1" runat="server" CreateUserUrl="~/PasswordRecover.aspx" CreateUserText="Forgot your password?"
      Height="58px" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt" OnAuthenticate="Login1_Authenticate">
        <TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <LayoutTemplate>
            <table border="0" cellpadding="1" cellspacing="0" style="border-collapse: collapse;
                height: 150px; width: 244px;">
                <tr>
                    <td>
                        <table border="0" cellpadding="0" style="height: 58px">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #6b696b">
                                    Log In</td>
                                <td align="center" colspan="1" style="font-weight: bold; color: white; background-color: #6b696b">
                                </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>
                                <td>
                                </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" Height="22px"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1">*</asp:RequiredFieldValidator>
                                </td>
                                <td>
                                </td>
                            </tr>
                            <tr>
                                <td colspan="2">
                                    <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                </td>
                                <td colspan="1">
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color: red">
                                    <br />
                                    <asp:LinkButton ID="LbTNPassword" runat="server" 
                                        PostBackUrl="~/PasswordRecover.aspx">Forgot your password?</asp:LinkButton>
                                    <br />
                                    <br />
                                    <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/StaffRegis.aspx">Create 
                                    an account</asp:LinkButton>
                                    &nbsp;<br />
                                    <br />
                                </td>
                                <td align="center" colspan="1" style="color: red">
                                    &nbsp;</td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    <br />
                                    <br />
                                    <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" 
                                        ValidationGroup="Login1" PostBackUrl="~/Transactions.aspx" 
                                        onclick="LoginButton_Click" />
                                </td>
                                <td align="right" colspan="1">
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </LayoutTemplate>
    </asp:Login>

    </asp:Content>

You had a Login control. Use Login1.UserName and Login1.Password property to access the textboxes.

Thank you. It really worked.
I have a problem with this statement as well. it sdays 'name 'InvalidCredentialsMessage' is not declared. please help me solve it

InvalidCredentialsMessage.Visible = True


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

If Membership.ValidateUser(Login1.UserName, Login1.Password) Then
' Log the user into the site
FormsAuthentication.RedirectFromLoginPage(Login1.UserName, Login1.RememberMe.checked)
End If
' If we reach here, the user's credentials were invalid
InvalidCredentialsMessage.Visible = True

End Sub

This article has been dead for over six months. Start a new discussion instead.