shorriga
asked on
CustomValidator Embedding inside DataList SelectedItemTemplate
My goal is to call the call the CustomAcctNumValidate procedure I wrote from a CustomValidator located inside a the SelectedItemTemplate of my DataList. The Textbox that is being validated is also in the SelectedItemTemplate of my DataList.
Code (I know this can be done with RangeValidator, but its a test for something else):
HTML:
<asp:CustomValidator id="cvAccountNum" runat="server" ErrorMessage="Account Number Must Be Less Than 25 Characters" OnServerValidate="CustomAc ctNumValid ate" ControlToValidate="txtAcct Num_SelIte m"></asp:C ustomValid ator>
VB.NET Code Behind:
Sub CustomAcctNumValidate(ByVa l source As Object, ByVal args As System.Web.UI.WebControls. ServerVali dateEventA rgs) Handles cvAccountNum.ServerValidat e
If args.Value.Length > 25 Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
The error is on the cvAccountNum object in the Handles clause: "Handles clause requres a WithEvents variable"
Declaring a WithEvents variable breaks the CustomValidator.
Any Suggestions?
Code (I know this can be done with RangeValidator, but its a test for something else):
HTML:
<asp:CustomValidator id="cvAccountNum" runat="server" ErrorMessage="Account Number Must Be Less Than 25 Characters" OnServerValidate="CustomAc
VB.NET Code Behind:
Sub CustomAcctNumValidate(ByVa
If args.Value.Length > 25 Then
args.IsValid = False
Else
args.IsValid = True
End If
End Sub
The error is on the cvAccountNum object in the Handles clause: "Handles clause requres a WithEvents variable"
Declaring a WithEvents variable breaks the CustomValidator.
Any Suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.