Reputation: 2282
I have a asp:rangevalidator control on a textbox that is used to enter the birthdate.
<asp:RangeValidator ID="valrDate" runat="server" ControlToValidate="txtDateOfBirth" MinimumValue="12/31/1950" MaximumValue="1/1/2012" Type="Date" text="Invalid Date" Display="Dynamic"/>
I would really like the ability to change the values of the minimum and maximum based on logic that will throw up a validation notice that indicates the date entered is outside of the allowed range of dates.
Can this be accomplished?
thanks tony
Upvotes: 0
Views: 2520
Reputation: 374
protected void RangeValidator5_Init(object sender, EventArgs e)
{
((RangeValidator)sender).MaximumValue = DateTime.Today.ToString("yyyy/MM/dd");
((RangeValidator)sender).MinimumValue = DateTime.Today.AddYears(-100).ToString("yyyy/MM/dd");
}
Upvotes: 0
Reputation: 7600
you can set it in code behind like:
protected void Page_Load(object sender, EventArgs e)
{
datetime dynamicMaxValue;
datetime dynamicMinValue;
//Code to compute dynamic Max/Min Value
//...
valrDate.MaximumValue = dynamicMaxValue; //Dynamic Max Value
valrDate.MinimumValue = dynamicMinValue; //Dynamic Min Value
}
Upvotes: 2