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;
- }


Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 27, 2017, 1:23 AM EST
Nitin SontakkeRank #264 · 9.6K reputationPosted Feb 26, 2017, 7:33 PM EST
Jes SieRank #1,285 · 1.3K reputationPosted Feb 27, 2017, 1:17 AM EST
Jes SieRank #1,285 · 1.3K reputationPosted Feb 27, 2017, 8:39 PM EST
Gnanavel SekarRank #333 · 7.5K reputationPosted Feb 27, 2017, 8:58 PM EST
Jes SieRank #1,285 · 1.3K reputationPosted Mar 1, 2017, 4:53 PM EST