1. Use images to Display error messages <Body>
<Form id = "form1" runat = "server">
<Asp: TextBox ID = "txtInt" runat = "server"> </asp: TextBox>
<Asp: CustomValidator ID = "CustomValidator1" runat = "server"
ClientValidationFunction = "validate_Integer" Display = "Dynamic"
ErrorMessage = "
</Asp: CustomValidator> <br/>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/>
</Form>
</Body>
The javascript function validate_Integer is called, so the script code is inserted between <Script type = "text/javascript" language = "javascript">
Function isInteger (s)
{
Var I;
For (I = 0; I <s. length; I ++)
{// Check whether the character is a number
Var c = s. charAt (I );
If (c <"0") | (c> "9") return false;
}
Return true;
}
Function validate_Integer (source, args)
{
Var txtintval = document. getElementById ("<% = txtInt. ClientID %> ");
If (! IsInteger (txtintval. value ))
{
Args. IsValid = false;
}
Else
{
Args. IsValid = true;
}
}
</Script>
2. Use RequiredFieldValidator for non-empty Verification
1. traditional verification methods
Specify the verification error message by setting its ErrorMessage attribute <Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox> & nbsp;
<Asp: RequiredFieldValidator ID = "RequiredFieldValidator1" runat = "server"
ControlToValidate = "TextBox1" EnableClientScript = "False" ErrorMessage = "* The input field cannot be blank! ">
</Asp: RequiredFieldValidator>
2. A JavaScript Prompt window is displayed.
You only need to assign the Text property of the verification control to a JavaScript code. <Asp: TextBox ID = "TextBox2" runat = "server"> </asp: TextBox> & nbsp;
<Asp: RequiredFieldValidator ID = "RequiredFieldValidator2" runat = "server"
ControlToValidate = "TextBox2" EnableClientScript = "False" ErrorMessage = "RequiredFieldValidator"
Text = "<script type = 'text/javascript '> alert (' * The input field cannot be blank! ') </Script> ">
</Asp: RequiredFieldValidator>
3. Verification with sound prompts. You can also use an image as an error message.
<Body>
<Form id = "form1" runat = "server">
<Asp: TextBox ID = "TextBox3" runat = "server"> </asp: TextBox> & nbsp;
<Asp: RequiredFieldValidator ID = "RequiredFieldValidator3" runat = "server"
ControlToValidate = "TextBox3"
EnableClientScript = "False"
ErrorMessage = "RequiredFieldValidator"
Text = "<bgsound src+'demo1.wav '>">
</Asp: RequiredFieldValidator>
<Asp: Button ID = "Button1" runat = "server" Text = "Button"/>
</Form>
</Body>
From: http://www.cnblogs.com/beniao/archive/2008/07/06/1236330.html