Solved

Custom Validator Not Working

Posted on 2004-09-30
8
613 Views
Last Modified: 2007-11-27
I have a custom validator on my aspx page that will just not work.  Below is the code in the code behind that should be called when I press the Save button, but it never is.  If I run in debug, this block of code is never even reached.  I have "Page.IsValid" being called in the Save code.  I also have a RequiredValidator on this same page that works fine so the problem is something with this validator.

For the record I have "EnableClientScript" set to false.  However, I even tried setting it to true and that did not work either.

I am missing something small?


CODE BEHIND:
Sub valSchedule_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles valSchedule.ServerValidate

        If Request.QueryString("Edit") <> "yes" Then
            If cboSchedule.SelectedItem.Value = "" Then
                args.IsValid() = False
            End If
        End If

    End Sub
0
Comment
Question by:mattgoolsby
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:Arvaris
ID: 12194703
Are you sure the custom validator is Enabled?

or you could manually try calling

valSchedule.Enabled = True
valSchedule.Validate()

in the function before you call If IsValid()

Also, make sure the button you're using doesn't have CausesValidation=False.

BTW - EnableClientScript only works if you have OnClientValidate set to a javascript function, otherwise it is ignored even if true
0
 

Author Comment

by:mattgoolsby
ID: 12195842
The validator is enabled, I tried manually doing the validate, CausesValidation is true.  I have a required field validate that fires fine when I press the button, so I think my issue lies only with the Custom Validator control.
0
 
LVL 2

Expert Comment

by:Arvaris
ID: 12199473
Have you set the required field validator EnableClientScript=False, because if there is a control that fires on client side and one the fires on server side, the client side gets clled first.  and if that fails, the server side validation never gets called.  So if you disable the client side validation on the required field validators, that will make it validate everything server side
0
 

Author Comment

by:mattgoolsby
ID: 12199494
EnableClientScript is false on both controls
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Expert Comment

by:Arvaris
ID: 12199542
Can you please post more of your code, like that aspx page and codebehind sections that deal with the button click...pretty much anything related to this part of the page.

There's probably just one simple little detail we both have overlooked.
0
 

Author Comment

by:mattgoolsby
ID: 12199579
Here is the code that I think is pertinent.  I will post more if needed.

ASPX HTML Code:

<form id="Form1" method="post" runat="server">
<p><b><asp:label id="lblSchedule" runat="server" cssclass="ScheduleTable">Create New Schedule</asp:label></b></p>
<TABLE id="Table1" style="LEFT: 10px; POSITION: absolute; TOP: 59px" height="464" cellSpacing="1" cellPadding="5" width="916" border="0">
      <TR>
            <TD align="right" width="212"><asp:label id="Label1" runat="server" CssClass="ScheduleTable">Budget:</asp:label></TD>
            <TD><asp:dropdownlist id="cboBudget" runat="server" CssClass="ScheduleTable" AutoPostBack="True" Width="400px"></asp:dropdownlist><asp:label id="lblBudget" runat="server" CssClass="ScheduleTable">Label</asp:label>
            <asp:RequiredFieldValidator id="valBudget" runat="server" ErrorMessage="Please Select a Budget" ControlToValidate="cboBudget" EnableClientScript="False" CssClass="ScheduleTable"></asp:RequiredFieldValidator></TD>
      </TR>
      <TR>
            <TD align="right" width="212"><asp:label id="Label2" runat="server" CssClass="ScheduleTable">Schedule Type:</asp:label></TD>
            <TD><asp:dropdownlist id="cboSchedule" runat="server" CssClass="ScheduleTable" Width="192px"></asp:dropdownlist><asp:label id="lblScheduleType" runat="server" CssClass="ScheduleTable">Label</asp:label>
            <asp:CustomValidator id="valSchedule" runat="server" CssClass="ScheduleTable" ErrorMessage="Please Enter a Schedule Type"
ControlToValidate="cboSchedule" EnableClientScript="False"></asp:CustomValidator></TD>
      </TR>

CODE BEHIND:

Private Sub cmdSaveBase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSaveBase.Click

            If Page.IsValid Then
                'Other code in here
            End If
End Sub

Sub valSchedule_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles valSchedule.ServerValidate

        If Request.QueryString("Edit") <> "yes" Then

            If cboSchedule.SelectedItem.Value = "" Then
                args.IsValid() = False
            End If
        End If

End Sub

0
 
LVL 2

Accepted Solution

by:
Arvaris earned 50 total points
ID: 12199615
Remove the ControlToValidate statement since you're manually identifying the control your validating in the function anyways.

I think I've had issues with that before
0
 

Author Comment

by:mattgoolsby
ID: 12199651
That worked perfectly.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

705 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

15 Experts available now in Live!

Get 1:1 Help Now