Solved

CustomValidator is not fired!

Posted on 2006-11-06
10
474 Views
Last Modified: 2007-12-19
Hi,  CustomValidator control is not fired when I submit the form, here is the code:


<asp:CustomValidator ControlToValidate="Departments" OnServerValidate="HasDepartment" Text="Employee should be assigned to a department" runat="server" ID="Departmentsvld" />


   Public Sub HasDepartment(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim blnHasDepartment As Boolean
        blnHasDepartment = False
        Dim LiThisOne As ListItem
        For Each LiThisOne In Departments.Items
            If LiThisOne.Selected Then
                blnHasDepartment = True
            End If
        Next
        If blnHasDepartment = True Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If

    End Sub

Do someone know what I am doing wrong?
0
Comment
Question by:Abdu_Allah
  • 5
  • 3
  • 2
10 Comments
 
LVL 13

Assisted Solution

by:jeebukarthikeyan
jeebukarthikeyan earned 100 total points
ID: 17881214
hi,

i will site a sample example

<asp:CustomValidator runat="server" id="custPrimeCheck"
ControlToValidate="txtPrimeNumber"
OnServerValidate="PrimeNumberCheck"
ErrorMessage="Invalid Prime Number" />

<script language="JavaScript">
<!--
  function CheckPrime(sender, args)
  {
    var iPrime = parseInt(args.Value);
    var iSqrt = parseInt(Math.sqrt(iPrime));

    for (var iLoop=2; iLoop<=iSqrt; iLoop++)
      if (iPrime % iLoop == 0)
      {
         args.IsValid = false;
         return;
      }

    args.IsValid = true;
  }
// -->
</script>

may be ur problem lies in the script

b u d d h a


0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17881425
I cannot see anything that may cause a problem!
0
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 17881520
hi,

can u just put ur javascript here

b u d d h a
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17881570
What javascript?
0
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 17881664
hi,
the validation script

b u d d h a
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17881695
It is in the question body.
Here it is again:

 Public Sub HasDepartment(ByVal source As Object, ByVal args As ServerValidateEventArgs)
        Dim blnHasDepartment As Boolean
        blnHasDepartment = False
        Dim LiThisOne As ListItem
        For Each LiThisOne In Departments.Items
            If LiThisOne.Selected Then
                blnHasDepartment = True
            End If
        Next
        If blnHasDepartment = True Then
            args.IsValid = True
        Else
            args.IsValid = False
        End If

    End Sub
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17881702
I used server side validation script and not client-side.
0
 
LVL 28

Expert Comment

by:strickdd
ID: 17883070
If you are using IE to test the validation, a custom validator with no "OnClientValidate" it will not fire until a postback happens. If you want it to fire when the controltovalidate loses focus then you need to have the javascript function on the page that will do client side validation.
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17884716
So how can I check if the listbox has a selected item(s) or not using javascript?
0
 
LVL 28

Accepted Solution

by:
strickdd earned 150 total points
ID: 17888621
for(int i=0; i<document.GetElementById("ListBoxIDHere").length; i++)
{
     if(document.GetElementById("ListBoxIDHere")[i].selected)
     {
        //this is selected
     }
}


The syntax is close. I would worry most about my capitalization.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

20 Experts available now in Live!

Get 1:1 Help Now