Click here to Skip to main content
16,012,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
How can i use a range validator to select any of the dates between the current date and next 30 dates after the current date and dates previous to current date should not be selected.can any one plz suggest some sample codes?
Posted

Hi you can do as below to get validation.

In Aspx page

XML
<tr>
     <td>
       <asp:TextBox ID="txtvalue" runat="server"></asp:TextBox>
       <asp:RangeValidator ID="Rvalid" runat="server"
ControlToValidate="txtvalue" ValidationGroup="Submit" ErrorMessage="your message"></asp:RangeValidator>
   </td>
</tr>
<tr>
   <td>
       <asp:Button ID="buttonclick"
ValidationGroup="Submit" runat="server" Text="Submit"
                         onclick="buttonclick_Click" />

   </td>
</tr>



In CS page on page load

C#
protected void Page_Load(object sender, EventArgs e)
         {
             Rvalid.MinimumValue = DateTime.Now.Date.ToString("MM-dd-yyyy");
             Rvalid.MaximumValue =
DateTime.Now.Date.AddDays(30).ToString("MM-dd-yyyy");
         }



Hope this will help you.... :)

Thanks
Naveen
 
Share this answer
 
Hi for this you should set range validation property in page load event:
C#
RangeValidator1.MinimumValue = DateTime.Now.Date.ToString("dd-MM-yy");
  RangeValidator1.MaximumValue = DateTime.Now.Date.AddDays(30).ToString("dd-MM-yy");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900