Problem with CustomValidator

Discussion in 'ASP .Net Web Controls' started by Nathan Sokalski, Jun 18, 2005.

  1. I want to make sure that the SelectedDate property of the Calendar control
    is later than the current date or that a certain checkbox is selected. I
    tried to use a CustomValidator control with the following code:

    Private Sub validTimeFrame_ServerValidate(ByVal source As System.Object,
    ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles
    validTimeFrame.ServerValidate

    If chkUnknown.Checked OrElse calTimeFrame.SelectedDate >= Date.Today Then

    args.IsValid = True

    Else

    args.IsValid = False

    End If

    End Sub


    As you can see, I check to see if chkUnknown is checked or if
    calTimeFrame.SelectedDate>= Date.Today. If either one is true, then I assign
    True to the IsValid property, otherwise I assign it a value of false.
    However, when I test the page it brings up the following error:

    [HttpException (0x80004005): Control 'calTimeFrame' referenced by the
    ControlToValidate property of 'validTimeFrame' cannot be validated.]
    System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String
    name, String propertyName)
    System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid()
    System.Web.UI.WebControls.BaseValidator.get_PropertiesValid()
    System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter writer)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    System.Web.UI.Control.Render(HtmlTextWriter writer)
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer)
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    System.Web.UI.Control.Render(HtmlTextWriter writer)
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    writer)
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer)
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)
    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter
    writer)
    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    System.Web.UI.Control.Render(HtmlTextWriter writer)
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    System.Web.UI.Page.ProcessRequestMain()

    Because this tells me nothing more than that the control cannot be
    validated, I do not know where to start. Any ideas? Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jun 18, 2005
    #1
    1. Advertising

  2. Nathan Sokalski

    Brock Allen Guest

    With a CustomValidator you don't need to assign the ControlToValidate property.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > I want to make sure that the SelectedDate property of the Calendar
    > control is later than the current date or that a certain checkbox is
    > selected. I tried to use a CustomValidator control with the following
    > code:
    >
    > Private Sub validTimeFrame_ServerValidate(ByVal source As
    > System.Object, ByVal args As
    > System.Web.UI.WebControls.ServerValidateEventArgs) Handles
    > validTimeFrame.ServerValidate
    >
    > If chkUnknown.Checked OrElse calTimeFrame.SelectedDate >= Date.Today
    > Then
    >
    > args.IsValid = True
    >
    > Else
    >
    > args.IsValid = False
    >
    > End If
    >
    > End Sub
    >
    > As you can see, I check to see if chkUnknown is checked or if
    > calTimeFrame.SelectedDate>= Date.Today. If either one is true, then I
    > assign True to the IsValid property, otherwise I assign it a value of
    > false. However, when I test the page it brings up the following error:
    >
    > [HttpException (0x80004005): Control 'calTimeFrame' referenced by the
    > ControlToValidate property of 'validTimeFrame' cannot be validated.]
    >
    > System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty
    > (String
    > name, String propertyName)
    > System.Web.UI.WebControls.CustomValidator.ControlPropertiesValid()
    > System.Web.UI.WebControls.BaseValidator.get_PropertiesValid()
    > System.Web.UI.WebControls.BaseValidator.Render(HtmlTextWriter
    > writer)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > System.Web.UI.Control.Render(HtmlTextWriter writer)
    > System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter
    > writer)
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > System.Web.UI.Control.Render(HtmlTextWriter writer)
    > System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
    > writer)
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter
    > writer)
    > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter
    > writer)
    >
    > System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter
    > writer)
    > System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
    > System.Web.UI.Control.Render(HtmlTextWriter writer)
    > System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
    > System.Web.UI.Page.ProcessRequestMain()
    > Because this tells me nothing more than that the control cannot be
    > validated, I do not know where to start. Any ideas? Thanks.
    >
     
    Brock Allen, Jun 18, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bill yeager

    customvalidator problem

    bill yeager, Aug 28, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,207
    Marina
    Aug 28, 2003
  2. Replies:
    3
    Views:
    1,567
    Peter Blum
    Jun 4, 2004
  3. Nathan Sokalski

    Problem with CustomValidator

    Nathan Sokalski, Jun 18, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,509
    Brock Allen
    Jun 18, 2005
  4. Replies:
    0
    Views:
    717
  5. Jeff
    Replies:
    2
    Views:
    1,092
Loading...

Share This Page