<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Client_Validation_Sample.aspx.cs" Inherits="Client_Validation_Sample" %>
<!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>
<script language="javascript" type="text/javascript">
function client_Validate()
{
if(document.getElementById("txtUserName").value=="")
{
alert('Required UserName');
return false;
}
else if(document.getElementById("txtPassWord").value=="")
{
alert('Required PassWord');
return false;
}
else if(document.getElementById("ddlDomain").selectedIndex==0)
{
alert('Please select Domain');
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 100px">
Select Domain</td>
<td style="width: 100px">
<asp:DropDownList ID="ddlDomain" runat="server">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Domain1</asp:ListItem>
<asp:ListItem>Domain2</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px">
Username</td>
<td style="width: 100px">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Password</td>
<td style="width: 100px">
<asp:TextBox ID="txtPassWord" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnValidate" runat="server" Text="Validate Client Validations" OnClick="btnValidate_Click" OnClientClick="return client_Validate();" /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>
<!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>
<script language="javascript" type="text/javascript">
function client_Validate()
{
if(document.getElementById("txtUserName").value=="")
{
alert('Required UserName');
return false;
}
else if(document.getElementById("txtPassWord").value=="")
{
alert('Required PassWord');
return false;
}
else if(document.getElementById("ddlDomain").selectedIndex==0)
{
alert('Please select Domain');
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 100px">
Select Domain</td>
<td style="width: 100px">
<asp:DropDownList ID="ddlDomain" runat="server">
<asp:ListItem>--Select--</asp:ListItem>
<asp:ListItem>Domain1</asp:ListItem>
<asp:ListItem>Domain2</asp:ListItem>
</asp:DropDownList></td>
</tr>
<tr>
<td style="width: 100px">
Username</td>
<td style="width: 100px">
<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px">
Password</td>
<td style="width: 100px">
<asp:TextBox ID="txtPassWord" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnValidate" runat="server" Text="Validate Client Validations" OnClick="btnValidate_Click" OnClientClick="return client_Validate();" /></td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Label ID="lblMessage" runat="server" Text=""></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>
Nice post
ReplyDelete