?
Solved

Custom Validator Not Working

Posted on 2004-09-30
8
Medium Priority
?
644 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:mattgoolsby
ID: 12199494
EnableClientScript is false on both controls
0
 
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 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

770 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