CustomValidator Embedding inside DataList SelectedItemTemplate

Posted on 2004-11-18
Last Modified: 2010-05-19
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):
<asp:CustomValidator id="cvAccountNum" runat="server" ErrorMessage="Account Number Must Be Less Than 25 Characters" OnServerValidate="CustomAcctNumValidate" ControlToValidate="txtAcctNum_SelItem"></asp:CustomValidator>
VB.NET Code Behind:
Sub CustomAcctNumValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvAccountNum.ServerValidate
If args.Value.Length > 25 Then

args.IsValid = False


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?
Question by:shorriga
    1 Comment
    LVL 28

    Accepted Solution

    Hi shorriga,

    I would suggest you to make CustomAcctNumValidate Public and remove the handles, because you have already set it by OnServerValidate declaration

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now