This is a migrated thread and some comments may be shown as answers.

Using CompareValidator For Dynamic RadDatePicker

3 Answers 130 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
DEEPAK
Top achievements
Rank 1
DEEPAK asked on 05 Nov 2008, 06:53 PM
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

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 06 Nov 2008, 09:14 AM
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.
0
DEEPAK
Top achievements
Rank 1
answered on 06 Nov 2008, 04:42 PM

Thanks Shinu this works like a charm.

Deepak
0
Koushik
Top achievements
Rank 1
answered on 11 Apr 2012, 05:01 PM
thanks.. its help me a lot..
Tags
Calendar
Asked by
DEEPAK
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
DEEPAK
Top achievements
Rank 1
Koushik
Top achievements
Rank 1
Share this question
or