Tech
Forums
Jobs
Books
Events
Live
Interviews
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
6
Reply
Restrict Selecting Date from Calendar Control
Hold On
Feb 26 2017 11:38 PM
178
Reply
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
;
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
6
)
Next Recommended Forum
Help required to add Nancy to existing asp.net web
How to send mail by using MVC 5