• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

Custom Validator Not Working

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
mattgoolsby
Asked:
mattgoolsby
  • 4
  • 4
1 Solution
 
ArvarisCommented:
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
 
mattgoolsbyAuthor Commented:
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
 
ArvarisCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
mattgoolsbyAuthor Commented:
EnableClientScript is false on both controls
0
 
ArvarisCommented:
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
 
mattgoolsbyAuthor Commented:
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
 
ArvarisCommented:
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
 
mattgoolsbyAuthor Commented:
That worked perfectly.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now