How to do basis validation using Javascript in ?


So many time, we will get scenario to do validation work or some other stuff using JavaScript in Here is the basic validation syntax using JavaScript in

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head id="Head1" runat="server">
    <script type="text/javascript">
                function doValidation() {
                    var name = document.getElementById("<%=txtEmpName.ClientID%>").value;
                    var empSal = document.getElementById("<%=txtEmpSal.ClientID%>").value;
                    var empAddress = document.getElementById("<%=txtEmpAddress.ClientID%>").value;
                    if (name == "") {
                        alert("Please enter the EmpName");
                    else if (empSal == "") {
                        alert("Please enter the EmpSal");
                    else if (isNaN(empSal)) {
                        alert("Invalid EmpSal");
                    else if (empAddress == "") {
                        alert("Please enter the EmpAddress");

    <form id="form1" runat="server">
        <asp:TextBox ID="txtEmpName" runat="server" />
        <br />
        <br />
        &nbsp;&nbsp;&nbsp;&nbsp; EmpSal
        <asp:TextBox ID="txtEmpSal" runat="server" />
        <br />
        <br />
        <asp:TextBox ID="txtEmpAddress" runat="server" />
        <br />
        <br />
        <asp:Button ID="btnClick" runat="server" OnClientClick="doValidation();return false;"
            Text="Submit" />


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.