Total Pageviews

25 July 2012

How making function for using validation on textbox in asp.net with example


Here, in this article we are using validation in textbox by using function on client side there are following process for creating a function and this function calling in asp.net button on client side and validation show in popup menu with instruction. Hope this article will be helpful for you.......






<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="DrLogin.aspx.cs" Inherits="DrLogin" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<script language="javascript" type="text/javascript">
//function to disable browser back button
function DisableBackButton() {
window.history.forward();
}
setTimeout("DisableBackButton()", 0);
window.onunload =function () { null };
</script>
<script type="text/javascript" language="javascript">
function amritvalidate() 
{
if (document.getElementById("<%=t1.ClientID%>").value == "")
{
alert("Enter Employee Name");
document.getElementById(
"<%=t1.ClientID%>").focus();
return false;
}
else
if(document.getElementById("<%=t2.ClientID%>").value=="")
{
alert("Enter correct Password");
document.getElementById("<%=t2.ClientID %>").focus();
return false;
}
else
if (document.getElementById("<%=ddl.ClientID%>").value == "Select") {

alert("Please select Designation");

document.getElementById(

"<%=ddl.ClientID %>").focus();
return false;
}
}
</script>

<script type="text/javascript">
function blinkIt() {
if (!document.all) return;
else {
for (i = 0; i < document.all.tags('blink').length; i++) {
s = document.all.tags('blink')[i];
s.style.visibility = (s.style.visibility =='visible') ? 'hidden' : 'visible';
}
}
}

</script>
<style type="text/css">
.blink
{
color: #dc1102;
font-weight: bold;
font-family: Verdana, Tahoma;
font-size: 14px;
}
</style>
</asp:Content>

<asp:Content ID="Content2"ontentPlaceHolderID="MainContent"Runat="Server">
<div>
<blink class="blink" align="Right"><asp:Image ID="Image2" runat="server" 
ImageUrl="~/image/logo.jpg" Height="54px" Width="300px" BackColor="#666699" 
BorderColor="Black" /><br />Welcome To STPL Online Management System</blink>
</div>
<div>
<table class="style3">
<tr>
<td class="style6" colspan="4" style="background-color: #0061AE" height="10px" 
width="911px">
<asp:Label ID="Label2" runat="server" Text="Employee DRSheet Details" BackColor="#0061AE" 
ForeColor="White" Height="18px"></asp:Label>


<asp:Label ID="Label1" runat="server" Height="18px" Text="LOGIN HERE" 
Width="100px" ForeColor="White" BackColor="#0061AE"></asp:Label>
</td>
</tr></table></div>
<div align="center"><fieldset><legend>Employee DRSheet</legend>
<table><tr><td>Employee Name</td><td><asp:TextBox ID="t1" runat="server" Height="21px" Width="170px"></asp:TextBox></td></tr>
<tr><td align="left">Password</td><td><asp:TextBox ID="t2" runat="server" 
Height="21px" Width="170px" TextMode="Password"></asp:TextBox></td></tr>
<tr><td align="left">Designation</td><td><asp:DropDownList ID="ddl" runat="server" Height="25px" Width="172px">
<asp:ListItem>Select</asp:ListItem>
<asp:ListItem>Supervisor</asp:ListItem>
<asp:ListItem>Project Manager</asp:ListItem>
<asp:ListItem>Project Coordinator</asp:ListItem>
<asp:ListItem>Asst.Programmer</asp:ListItem>
<asp:ListItem>Asst.Acountant</asp:ListItem>
<asp:ListItem>Tech. Support Executive</asp:ListItem>
<asp:ListItem>SEO Executive</asp:ListItem>
<asp:ListItem>Hr Executive</asp:ListItem>
<asp:ListItem>Admin HR</asp:ListItem>
<asp:ListItem>Sales Executive</asp:ListItem>
<asp:ListItem>DTP Operator</asp:ListItem>
<asp:ListItem>Assamese Translator</asp:ListItem>
<asp:ListItem>Tamil Translator</asp:ListItem>
</asp:DropDownList></td></tr>

<tr><td></td><td><asp:Button ID="bt" runat="server" Text="Login" 
OnClientClick="return amritvalidate();" onclick="bt_Click" />

<asp:Button ID="bt2" runat="server" text="Cancel" onclick="bt2_Click" /></td></tr>
</table>
</fieldset></div><br />
<br />
<br />
<div style="background-color: #0061AE">
<asp:Label ID="Label3" runat="server" BackColor="#0061AE" Height="18px" 
Width="911px"></asp:Label>
</div>
</asp:Content>




 

Contact Form

Name

Email *

Message *