Introduction:
This article is helps to how to check Standard
Username and Password for login screen in asp.net using Vb.net
Designing
Page (Source Code):
<%@ Page
Language="vb"
AutoEventWireup="false"
CodeBehind="login.aspx.vb"
Inherits="Asp_Dot.login"
%>
<!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>Asp Basic Login</title>
<script src="../../jquery-1.9.1.js"
type="text/javascript"></script>
<style type="text/css">
.Mandatory
{
float: left;
background-color: Transparent;
color: red;
display: inline-block;
height: 15px;
margin-left: -10px;
margin-top: 5px;
width: 10px;
}
.Column
{
width: 98.5%;
display: inline-block;
padding: 5px;
}
.Column span
{
width: 15%;
float: left;
padding: 3px;
}
.Column input[type="text"],
.Column input[type="password"]
{
width: 25%;
float: left;
margin-right: 10px;
}
.Column input[type="submit"]
{
float: left;
margin-top: -1px;
}
</style>
<script type="text/javascript">
function ValidateButton() {
if ($.trim($('#<%=
txtUserName.ClientID %>').val())
== "") {
alert("User Name
Required");
$('#<%=
txtUserName.ClientID %>').focus()
return false;
}
else if ($.trim($('#<%=
txtpassword.ClientID %>').val())
== "") {
alert("Password
Required");
$('#<%=
txtpassword.ClientID %>').focus()
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
div class="Column">
<asp:Label ID="lblUserName" runat="server" Text="User Name"></asp:Label>
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
<span class="Mandatory">*</span></div>
<div class="Column">
<asp:Label ID="lblPassword" runat="server" Text="Password"></asp:Label>
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server"></asp:TextBox>
<span class="Mandatory">*</span></div>
<div class="Column" style="padding-left: 150px">
<asp:Button ID="btnLogin" runat="server" BorderColor="Aqua" OnClientClick="javascript:return ValidateButton()"
Text="Login" /></div>
</div>
</form>
</body>
</html>
VB.NET:
Private Sub btnLogin_Click(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles btnLogin.Click
If
txtUserName.Text = "asp" And txtpassword.Text = "asp"
Then
MsgBox("Login
Successfully")
Else
MsgBox("Invalid
User Name / Password")
End If
End Sub
C#:
private
void btnLogin_click(object
sender, EventArgs e)
{
if
((txtUserName.Text == "asp")
&& (txtpassword.Text == "asp"))
{
string
ScriptText = "alert('Login
Successfully')";
ScriptManager.RegisterStartupScript(this,
GetType(), "Script", ScriptText, true);
}
else
{
string
ScriptText = "alert('Invalid User Name /
Password')";
ScriptManager.RegisterStartupScript(this,
GetType(), "Script", ScriptText, true);
}
}
Demo:
0 comments:
Post a Comment