Using CompareValidator For Dynamic RadDatePicker

4 posts, 1 answers
  1. DEEPAK
    DEEPAK avatar
    3 posts
    Member since:
    Nov 2008

    Posted 05 Nov 2008 Link to this post

    Hello All,
          I am working ASP.net 2008, SSRS. I have successfully created Dynamic controls based on the selected report Parameter DataType and everything works fine.
         I am trying to add validations by using the Validator controls for the dynamic RadDatePicker controls. In my scenario, I am creating two RadDatePicker controls each for StartDate and EndDate. My condition is : StartDate cannot be greater than the EndDate.
         When I assign ControlToValidate and ControlToCompare for dynamically created RadDatePicker controls it is causing me problems. The error is:

    Control 'dtE' referenced by the ControlToCompare property of 'dtCmpVal' cannot be validated.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Web.HttpException: Control 'dtE' referenced by the ControlToCompare property of 'dtCmpVal' cannot be validated.

    Source Error:

    An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

    Stack Trace:

    [HttpException (0x80004005): Control 'dtE' referenced by the ControlToCompare property of 'dtCmpVal' cannot be validated.]
       System.Web.UI.WebControls.BaseValidator.CheckControlValidationProperty(String name, String propertyName) +1840513
       System.Web.UI.WebControls.CompareValidator.ControlPropertiesValid() +1735335
       System.Web.UI.WebControls.BaseValidator.OnPreRender(EventArgs e) +33
       System.Web.UI.Control.PreRenderRecursiveInternal() +86
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Control.PreRenderRecursiveInternal() +170
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
    



    Please help me , in figuring out to add Compare Validator or RangeValidator using Dynamic Controls.

    --Deepak
  2. Answer
    Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Nov 2008 Link to this post

    Hi Deepak,

    You can add CompareValidator dynamically to check the start and end date. Please try the below code snippet.

    C#
            CompareValidator compareValidator = new CompareValidator(); 
            compareValidator.ID = "Validator"
            compareValidator.ControlToValidate = "StartDate"// StartDate is the ID of the first DatePicker 
            compareValidator.ControlToCompare = "EndDate";// EndDate is the ID of the second DatePicker 
            compareValidator.Operator = ValidationCompareOperator.LessThan; 
            compareValidator.Type = ValidationDataType.Date; 
            compareValidator.ErrorMessage = "The end date must be after the start one."
            this.form1.Controls.Add(compareValidator); 


    Regards,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. DEEPAK
    DEEPAK avatar
    3 posts
    Member since:
    Nov 2008

    Posted 06 Nov 2008 Link to this post


    Thanks Shinu this works like a charm.

    Deepak
  5. Koushik
    Koushik avatar
    1 posts
    Member since:
    Apr 2012

    Posted 11 Apr 2012 Link to this post

    thanks.. its help me a lot..
Back to Top