一般使用ErrorMessage属性: ErrorMessage="请在TextBox1中输入字符"
1<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="请在TextBox1中输入字符"></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
假如要用到图片的话,使用的方法是:ErrorMessage='<img src="images/cai.jpg"></a>'2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="请在TextBox1中输入字符"></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
1<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage='<img src="images/cai.jpg"></a>'></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
注意单引号和双引号的使用2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage='<img src="images/cai.jpg"></a>'></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
假如要用声音的话,当然是同样的道理
1 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage='<bgsound src="E:\vs2005first\WebSite3\music\MTA_007.WAV" loop="1">' EnableClientScript="false"></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
与插入图片不同的是,需要把Script禁用,否则无论验证不验证,当页面loaded是都会有背景声,所以加入EnableClientScript="false",就ok了2 <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
3 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage='<bgsound src="E:\vs2005first\WebSite3\music\MTA_007.WAV" loop="1">' EnableClientScript="false"></asp:RequiredFieldValidator>
4 <asp:Button runat="server" ID="haha" Text="提交" />
还有一种插入背景声的方法,不过不太经常用
<IMG height=0 loop=infinite dynsrc=http://www.csdbzx.net/zq/许巍-蓝莲花.wma width=0 border=0>
(适用于.net2.0)