Runtime validation Webcontrol

B

brandonjack007

I have a webcontrol that extends from
System.Web.UI.WebControls.WebControl. It has 3 properties
SelectedDate, MaximumDate,MinimumDate. During design time I use
ArgumentException to ensure
MinimumDate<SelectedDate<MaximumDate. How can I achieve this
validation during runtime.
 
J

Jesse Houwing

* (e-mail address removed) wrote, On 31-7-2007 22:24:
I have a webcontrol that extends from
System.Web.UI.WebControls.WebControl. It has 3 properties
SelectedDate, MaximumDate,MinimumDate. During design time I use
ArgumentException to ensure
MinimumDate<SelectedDate<MaximumDate. How can I achieve this
validation during runtime.

You can add a range validator to the user control. set it's minimum
value and maximumvalue and the control to validate and you're all set.

Jesse
 
J

Jesse Houwing

* (e-mail address removed) wrote, On 31-7-2007 22:24:
I have a webcontrol that extends from
System.Web.UI.WebControls.WebControl. It has 3 properties
SelectedDate, MaximumDate,MinimumDate. During design time I use
ArgumentException to ensure
MinimumDate<SelectedDate<MaximumDate. How can I achieve this
validation during runtime.

I was too fast in answering I see now. You're inheriting from
WebControl, not WebUserControl.

In that case you need to implement the IValidator interface and provide
the correct validation details in there.

Jesse
 
B

brandonjack007

I implement IValidator interface in the control
Is this the correct way cos it fails....
public bool IsValid
{
get {return mIsValid;}
set { mIsValid = value;}
}

public string ErrorMessage
{
get { return mErrorMessage; }
set { mErrorMessage = value; }
}

public virtual void Validate()
{
this.IsValid = true;
if(!IsDate(this.selectedDate.ToString()))
{
this.IsValid = false;
}
if (this.selectedDate<this.MinimumDate ||
this.selectedDate>this.MaximumDate)
{
this.IsValid = false;
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top