日期:2009-11-18  浏览次数:20419 次

在ASP.net 1.1中,对于验证类控件,在使用时,遇到有的不需要验证的控件时,是十分麻烦的,就是说不可能有选择验证某些控件,而在ASP.net 2.0中,新增加了validationgroup属性,可以指定验证某些控件,例子如下:



<HTML>

<body>

<form runat=“server”>

<ASP:textbox id=“TextBox1” runat=“server”/>

<ASP:requiredfieldvalidator ValidationGroup=“Group1”

ErrorText=“Need to Fill in Value!”

ControlToValidate=“TextBox1”

runat=“server”/>



<ASP:textbox id=“TextBox2” runat=“server”/>

<ASP:requiredfieldvalidator ValidationGroup=“Group2”

ErrorText=“Need to Fill in Value!”

ControlToValidate=“TextBox2”

runat=“server”/>



<ASP:button text=“Group1” ValidationGroup=“Group1” runat=“server”/>

<ASP:button text=“Group2” ValidationGroup=“Group2” runat=“server”/>

</form>

</body>

</HTML>