Live Chat Icon For mobile
Live Chat Icon

How can I set the maximum and minimum value for RangeValidator based on two dates

Platform: ASP.NET| Category: Controls

<asp:textbox id='TextBox1' runat='server'></asp:textbox>
<asp:rangevalidator id='RangeValidator1' type='Date' controltovalidate='TextBox1' runat='server' errormessage='Not in range' />
<asp:button id='Button1' runat='server' text='Button'></asp:button>

VB.NET


...
Dim dtMinDate As DateTime
Dim dtMaxDate As DateTime
dtMinDate = Convert.ToDateTime('04/25/04')
dtMaxDate = Convert.ToDateTime('10/17/04')
RangeValidator1.MinimumValue = dtMinDate
RangeValidator1.MaximumValue = dtMaxDate
TextBox1.Text = dtMaxDate.ToShortDateString
RangeValidator1.ErrorMessage = 'Not in Range of ' & dtMinDate.ToShortDateString() & ' to ' & dtMaxDate.ToShortDateString()

C#


DateTime dtMinDate ; 
DateTime dtMaxDate ; 
dtMinDate = Convert.ToDateTime('04/25/04');
dtMaxDate = Convert.ToDateTime('10/17/04');
RangeValidator1.MinimumValue = dtMinDate.ToShortDateString () ;
RangeValidator1.MaximumValue = dtMaxDate.ToShortDateString () ;
TextBox1.Text = dtMaxDate.ToShortDateString();
RangeValidator1.ErrorMessage = 'Not in Range of ' + dtMinDate.ToShortDateString() + ' to ' + dtMaxDate.ToShortDateString();

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.