Hello All!
I am working on a project where usernames can be easily misspelled. As such, after assessing the security risks, we have decided to implement a dropdownlist in the Login control of our membership interface. The problem is it does not want to work! I keep getting the following application error: "BC30451: 'LoginUser' is not declared. It may be inaccessible due to its protection level."
Below is my code. Anyone have any ideas?
<asp:Login ID="Login1" runat="server" style="margin-left:auto; margin-right:auto;"
DestinationPageUrl="~/PortalSys/PortalHome.aspx" Width="336px">
<LayoutTemplate>
<table border="0" cellpadding="1" cellspacing="0"
style="border-collapse:collapse;">
<tr>
<td>
<table border="0" cellpadding="0" style="width:336px;">
<tr>
<td align="center" colspan="2">
Log In</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User
Name:</asp:Label>
</td>
<td>
<aspropDownList ID="UsersList" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
DataTextField="UserName" DataValueField="UserName" OnSelectedIndexChanged="UserSelected">
<asp:ListItem Text="-- select user name --" Value="">
</asp:ListItem>
</aspropDownList>
<br />
<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 me next time." />
</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" Text="Log In"
ValidationGroup="Login1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login></form>
VB Code-Behind:
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Security
Imports System.Security.Permissions
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim UsersList As DropDownList = TryCast(LoginUser.FindControl("UsersList"), DropDownList)
UsersList.DataSource = Membership.GetAllUsers()
UsersList.DataBind()
End If
End Sub
Protected Sub UserSelected(ByVal sender As Object, ByVal e As EventArgs)
LoginUser.UserName = TryCast(sender, DropDownList).SelectedValue
End Sub
End Class
I am working on a project where usernames can be easily misspelled. As such, after assessing the security risks, we have decided to implement a dropdownlist in the Login control of our membership interface. The problem is it does not want to work! I keep getting the following application error: "BC30451: 'LoginUser' is not declared. It may be inaccessible due to its protection level."
Below is my code. Anyone have any ideas?
<asp:Login ID="Login1" runat="server" style="margin-left:auto; margin-right:auto;"
DestinationPageUrl="~/PortalSys/PortalHome.aspx" Width="336px">
<LayoutTemplate>
<table border="0" cellpadding="1" cellspacing="0"
style="border-collapse:collapse;">
<tr>
<td>
<table border="0" cellpadding="0" style="width:336px;">
<tr>
<td align="center" colspan="2">
Log In</td>
</tr>
<tr>
<td align="right">
<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User
Name:</asp:Label>
</td>
<td>
<aspropDownList ID="UsersList" runat="server" AppendDataBoundItems="true" AutoPostBack="true"
DataTextField="UserName" DataValueField="UserName" OnSelectedIndexChanged="UserSelected">
<asp:ListItem Text="-- select user name --" Value="">
</asp:ListItem>
</aspropDownList>
<br />
<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 me next time." />
</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" Text="Log In"
ValidationGroup="Login1" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</LayoutTemplate>
</asp:Login></form>
VB Code-Behind:
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.Security
Imports System.Security.Permissions
Partial Class Login
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim UsersList As DropDownList = TryCast(LoginUser.FindControl("UsersList"), DropDownList)
UsersList.DataSource = Membership.GetAllUsers()
UsersList.DataBind()
End If
End Sub
Protected Sub UserSelected(ByVal sender As Object, ByVal e As EventArgs)
LoginUser.UserName = TryCast(sender, DropDownList).SelectedValue
End Sub
End Class