JavaScript验证

时间:2011-02-15 10:47:53

标签: javascript asp.net

我想执行客户端验证..我想这样做,当没有输入名字时,会显示一个消息框,其中显示缺少名字和所有文本框相同..但我不能这样做:/ ..请帮忙! :/这是我的代码:

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

    电话簿                    名字         

    <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>

1 个答案:

答案 0 :(得分:1)

使用ASP.NET RequiredFieldValidator Control。使用ASP.NET验证字段。

more here

使用它像:

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