Abid Ali
Abid Ali

Reputation: 1747

JavaScript Validations

i want to perform client side validations.. i want to do such that when the firstname is not entered, there shows a messagebox in which it says that firstname is missing and same for all the textboxes.. but i can`t do so :/.. please help! :/ here is my code :

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

Phone Book First Name

    <br />

    <label id = "LastNameLabel" Text= "First Name" > Last Name</label>
    <asp:TextBox ID="LastNameTextBox" runat="server"></asp:TextBox>
    <br />

    <label id = "HomePhoneNumberLabel" Text= "First Name" >Home PhoneNumber</label>
    <asp:TextBox ID="HomePhoneNumberTextBox" runat="server"></asp:TextBox>
    <br />

    <label id = "CellNumberLabel" Text= "First Name" >Cell PhoneNumber</label>
    <asp:TextBox ID="CellNumberTextBox" runat="server"></asp:TextBox>
    <br />

    <label id = "EmailAddressLabel" Text= "First Name" >Email Address</label>
    <asp:TextBox ID="EmailAddressTextBox" runat="server"></asp:TextBox>
    <br />

    <label id = "HomeAddressLabel" Text= "First Name" >Home Address</label>
    <asp:TextBox ID="HomeAddressTextBox" runat="server"></asp:TextBox>
    <br />

    <label id = "NICNumberLabel" Text= "First Name" >NIC Number </label>
    <asp:TextBox ID="NICNumberTextBox" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="AddButton" runat="server" Text="Add Record" 
        onclick="AddButton_Click" />

</div>
</form>
<script type="text/javascript">
if()
{
}

</script>

Upvotes: 0

Views: 122

Answers (1)

Caspar Kleijne
Caspar Kleijne

Reputation: 21864

Use the ASP.NET RequiredFieldValidator Control. to validate the fields with ASP.NET.

more here

use it like:

 <asp:RequiredFieldValidator id="LastNameTextBoxRequiredFieldValidator"
             ControlToValidate="LastNameTextBox"
             Display="Static"
             Text="enter text please!"
             runat="server">

Upvotes: 1

Related Questions