I have 2 textboxes, the first textbox is a date from the database and the second textbox is asp:calendar. Now, this is what I want to achieve: Textbox2 cannot select a date older that what is in textbox1. Below is my code but it is not working.
html and c# code:
- <ajaxToolkit:CalendarExtender ID="calFirst" runat="server"
- TargetControlID="TextBox1"
- CssClass="MyCalendar"
- Format="MMMM d, yyyy" />
-
- <asp:TextBox ID="TextBox1" runat="server">asp:TextBox>
-
- <br>
- <asp:TextBox ID="TextBox4" runat="server">asp:TextBox>
-
- <asp:ImageButton ID="ImageButton1" runat="server" Height="17px"
- ImageUrl="~/img/calendar.png" OnClick="ImageButton1_Click" Width="21px" />
- <asp:Calendar ID="Calendar1" runat="server"
- OnSelectionChanged="Calendar1_SelectionChanged"
- OnDayRender="Calendar1_DayRender" Visible="False">asp:Calendar>
- protected void Calendar1_SelectionChanged(object sender, EventArgs e)
- {
- TextBox4.Text = Calendar1.SelectedDate.ToShortDateString();
- Calendar1.Visible = false;
- }
-
- protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
- {
- DateTime date = Convert.ToDateTime(TextBox1.Text);
- if (e.Day.Date > date)
- {
- e.Cell.Enabled = false;
- e.Day.IsSelectable = false;
- }
- }
-
- protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
- {
- Calendar1.Visible = true;
- }