- Login Web Server Control
in ASP.NET environment,This article describes you how to work with Login Web Control. The primary purpose of the Login control is to provide the UI control to authenticate into the website.In other words, The Login control is a composite control that provides all the common UI elements needed to authenticate a user on a Web site. The following three elements are required for all login sections:
- user name -unique name to identify the user.
- password -to verify the identity of the user.
- login button -to send the login information to the server.
Styles
- BorderPadding - The space between the control contents and the control's border.
- CheckBoxStyle -Remember Me checkbox.
- FailureTextStyle - Login failure text.
- InstructionTextStyle -Instructional text on the page that tells users how to use the control.
- LabelStyle -Labels for all input fields, such as text boxes.
- TextBoxStyle -Text entry input fields.
- TitleTextStyle -Title text.
- ValidatorTextStyle -Text displayed to the user when a login attempt is unsuccessful due to validation errors.
- HyperLinkStyle -Links to other pages.
- LoginButtonStyle -Login button.
The following code snippets represents that a Login control to provide a UI for logging in to a Web site.
in .aspx.cs page,
-
bool IsValidEmail(string strIn)
{
return Regex.IsMatch(strIn, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]
{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$");
}
void OnLoggingIn(object sender, System.Web.UI.WebControls.LoginCancelEventArgs e)
{
if (!IsValidEmail(log1.UserName))
{
log1.InstructionText = "e-mail address is invalid.";
log1.InstructionTextStyle.ForeColor = System.Drawing.Color.Red;
e.Cancel = true;
}
else
{
log1.InstructionText = String.Empty;
}
}
void OnLoginError(object sender, EventArgs e)
{
log1.HelpPageText = "logging in...";
log1.PasswordRecoveryText = "Forgot your password?";
}
-
The following code snippets explains how to work with MembershipProvider property of Login control .
in .aspx.cs file,
-
namespace Samples.AspNet.Controls
{
public sealed class CustomLogin : Login
{
public CustomLogin() { }
protected override void OnLoggingIn(LoginCancelEventArgs e)
{
DropDownList list = (DropDownList)this.FindControl("domain");
this.MembershipProvider = list.SelectedValue;
base.OnLoggingIn(e);
}
protected override void CreateChildControls()
{
LayoutTemplate = new Temp1();
base.CreateChildControls();
}
}
public class Temp1 : ITemplate
{
void ITemplate.InstantiateIn(Control container)
{
TextBox UName = new TextBox();
UName.ID = "UName";
TextBox password = new TextBox();
password.ID = "password";
CheckBox remember = new CheckBox();
remember.ID = "RememberMe";
remember.Text = "Don't forget me!";
Literal failure = new Literal();
failure.ID = "FailureText";
DropDownList domain = new DropDownList();
domain.ID = "Domain";
domain.Items.Add(new ListItem("SqlMembers"));
domain.Items.Add(new ListItem("SqlMembers2"));
Button submit = new Button();
submit.CommandName = "login";
submit.Text = "LOGIN";
container.Controls.Add(new LiteralControl("UName:"));
container.Controls.Add(UName);
container.Controls.Add(new LiteralControl("
Password:"));
container.Controls.Add(password);
container.Controls.Add(new LiteralControl("
"));
container.Controls.Add(remember);
container.Controls.Add(new LiteralControl("
Domain:"));
container.Controls.Add(domain);
container.Controls.Add(new LiteralControl("
"));
container.Controls.Add(failure);
container.Controls.Add(new LiteralControl("
"));
container.Controls.Add(submit);
}
}
}
-
- Related Links
-
fc942c0d-7f6e-4c75-940b-0c56f760b4e0|0|.0