Range Validator MinValue and MaxValue date

songoku107723

Member
Joined
Apr 18, 2008
Messages
12
Programming Experience
Beginner
Hello guys, i need some help for range validator.

i have textbox with value like 23 / Jul / 2012 and i want to validate if the value is value can't be outside the range day +1 and day -1, so if we entry 25 / Jul / 2012 or 21 / Jul / 2012 it's will be said invalid date selection.

here's my code in .aspx :
<asp:TextBox ID="TxtStartDate" runat="server" Enabled="false" TabIndex="5" Width="180px" />
<asp:Image ID="ImgStartDate" runat="server" ImageUrl="~/WFile_Images/ImgCalendar.png" TabIndex="6" />
<asp:CalendarExtender ID="CeStartDate" runat="server" CssClass="MyCalendar" Enabled="True" PopupButtonID="ImgStartDate" TargetControlID="TxtStartDate" DaysModeTitleFormat="dd / MMM / yyyy" Format="dd / MMM / yyyy" />
<asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Invalid Date Selection" ControlToValidate="TxtStartDate" ValidationGroup="VgTravellingSchedule" Type="Date" Text="*" Display="Dynamic" />
<asp:Button ID="BtnSave" runat="server" Text="Save" ToolTip="Save Data" TabIndex="13" ValidationGroup="VgTravellingSchedule" />

and i set the minvalue and maxvalue in from the code behind in page_load event.

here's my code in .vb :

Protected Sub WF_TravellingSchedule_Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
If Not Page.IsPostBack Then
RangeValidator1.MinimumValue = Today.AddDays(-1).ToString("dd / MMM / yyy")
RangeValidator1.MaximumValue = Today.AddDays(1).ToString("dd / MMM / yyyy")
End If
Catch ex As Exception
Throw New Exception("Protected Sub WF_TravellingSchedule_Page_Load Error : " & vbCrLf & ex.Message.ToString)
End Try
End Sub

with that's code i getting error like : The value '24 / Jul / 2012' of the MaximumValue property of 'RangeValidator1' cannot be converted to type 'Date'.

please help me... Thanx before :)
 
Thanx for reply JohnH, i think the problem is like what you said : culture-neutral format,
is there another way to fix this problem without changing the culture format ? i can't set the format into "yyyy/MM/dd" because i have to use this format "dd / MMM / yyyy"

Thanx verry much JohnH :) sorry for my bad english :D
 
You're misunderstanding, the validator needs the min/max values in a string format it can parse to validating type. "yyyy/MM/dd" format can be used for all cultures, that is what it means to be culture-neutral.
 

Latest posts

Back
Top