<div class=ForumPostContentText id=ctl00_ctl01_bcr_ctl00___PostRepeater_ctl03_PostViewWrapper>Hi, dear friends. You all may know something about members of calendar and its extender. For example how would we do to validate a selected date within
a target range, say must be a weekday, first of the month, end of the month, and so forth? Please advise. Thanks </div>
Please mark this post as "Answer" and earn a point.
There is nothing integral to the Calendar currently to support this kind of validation within the behavior itself. You can still enforce the validation against the selected date by using an ASP.NET Validator (RangeValidator, RegExValidator, or CustomValidator)
as your needs may dicatate.
I only see an inconvenient in changing that file, and others file from the controltoolkit source. When the Ajax Control Toolkit get a newer version, you will need to make the modifications again or worst, the new version will give the funcionallity you were
looking when you changed the files, and you need to change all your projects to comply with the new features.
But this is only my two cents.[:P]
You have a point, but in this case there are only two simple lines. And I guess I'll have to change my files in the case of a newer release anyway, even without this mod. (as I did in the AJAX 1.0 release)
But it's a cost x benefit question, in my case the cost is minimal, and the benefit is huge, I think...
Rafael Soares
Web Developer
ASP.NET / C# / (X)HTML / CSS / JavaScript
http://rafasoares.wordpress.com (sorry, blog is just in portuguese... english site coming soon! ;] )
<div class="ForumPostContentText" id="ctl00_ctl01_bcr_ctl00___PostRepeater_ctl03_PostViewWrapper">Hi, dear friends. You all may know something about members of calendar and its extender. For example how would we do to validate a selected date within
a target range, say must be a weekday, first of the month, end of the month, and so forth? Please advise. Thanks </div>
I think you may be mixing the calendarextender and the calendar control up. They're really not related- calendarextender is an extender for the textbox control.
That said to do the type of validation you're talking about for either one you'll need to write a customvalidator. You can in javascript,in codebehind, or both I only did your first example and only did it in codebehind:
aspx page:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="You may not select days which fall on a weekend" ControlToValidate="TextBox1" OnServerValidate="CheckWeekend" ValidationGroup="VGroup1"></asp:CustomValidator>
<br />
<asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="VGroup1" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1">
</ajaxToolkit:CalendarExtender>
code behind:
protected void CheckWeekend(object sender, ServerValidateEventArgs e)
{
switch (Convert.ToDateTime(TextBox1.Text).DayOfWeek)
{
// saturday or sunday are invalidcase DayOfWeek.Saturday:
case DayOfWeek.Sunday:
e.IsValid = false;
break;
// everything else is validdefault:
e.IsValid = true;
break;
}
}
Hehe
Paulo, I just saw your post after I've posted. But thank you anyway. [:D]
Additionally, I've changed the control's source (CalendarBehavior.js) and added the bold lines in the following code:
set_selectedDate : function(value) {
var elt = this.get_element();
if (this._selectedDate != value) {
this._selectedDate = value;
this._selectedDateChanging = true;
var text = "";
if (value) {
text = value.localeFormat(this._format);
}
if (text != elt.value) {
elt.value = text;
this._fireChanged();
}
this._selectedDateChanging = false;
this.invalidate();
this.hide();
elt.blur();
this.raisePropertyChanged("selectedDate");
}
},
That way, I won't need to use the JS function in every page I use the calendar (and there are lots of them). And since I want the Calendar to
always have this behavior, this is just the best solution for me. [;)]
I am having troubles getting this to work with Mozilla. If I add the OnClientDateSelectionChanged to the extender, the calendar stops showing up. Has any body experienced this? Or am I doing something wrong? I am having the exact functions mentioned in
the above posts!
Also, it works fine in Mozilla if I add those 2 lines in the control's source (CalendarBehavior.js). Am I missing anything using the RegisterclientScriptblock solution?
Guys, there's not need for registering client scripts or anything like that...
Just setting up the following will do the job:
OnClientDateSelectionChanged="focus"
That will simply will execute "window.focus();" and that will make the calendar control to close in a clean way...
Oh, that's sweet!
Yet, it's something you'll have to do in every calendar extender you have...
But good solution at all! ;)
Rafael Soares
Web Developer
ASP.NET / C# / (X)HTML / CSS / JavaScript
http://rafasoares.wordpress.com (sorry, blog is just in portuguese... english site coming soon! ;] )
thuhue
All-Star
15625 Points
3146 Posts
Re: Getting Calender to close on date selection
Feb 06, 2007 05:31 PM|LINK
rbuckton
Member
547 Points
124 Posts
Re: Getting Calender to close on date selection
Feb 06, 2007 05:43 PM|LINK
Senior Consultant
Microsoft
cruentus
Member
40 Points
21 Posts
Re: Getting Calender to close on date selection
Feb 06, 2007 07:32 PM|LINK
You have a point, but in this case there are only two simple lines. And I guess I'll have to change my files in the case of a newer release anyway, even without this mod. (as I did in the AJAX 1.0 release)
But it's a cost x benefit question, in my case the cost is minimal, and the benefit is huge, I think...
Web Developer
ASP.NET / C# / (X)HTML / CSS / JavaScript
http://rafasoares.wordpress.com
(sorry, blog is just in portuguese... english site coming soon! ;] )
danehrig
Member
85 Points
53 Posts
Re: Getting Calender to close on date selection
Feb 06, 2007 08:40 PM|LINK
I think you may be mixing the calendarextender and the calendar control up. They're really not related- calendarextender is an extender for the textbox control.
That said to do the type of validation you're talking about for either one you'll need to write a customvalidator. You can in javascript,in codebehind, or both I only did your first example and only did it in codebehind:
aspx page:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:CustomValidator ID="CustomValidator2" runat="server" ErrorMessage="You may not select days which fall on a weekend" ControlToValidate="TextBox1" OnServerValidate="CheckWeekend" ValidationGroup="VGroup1"></asp:CustomValidator> <br /> <asp:Button ID="Button1" runat="server" Text="Button" ValidationGroup="VGroup1" /> <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="TextBox1"> </ajaxToolkit:CalendarExtender>code behind:
dawtips
Member
22 Points
7 Posts
Re: Getting Calender to close on date selection
Feb 14, 2007 09:42 PM|LINK
Worked great for me, thanks!
mr_breaker
Member
320 Points
187 Posts
Re: Getting Calender to close on date selection
Jun 14, 2007 03:08 PM|LINK
Does anyone know if the fix stated in the last post will be implemented into a release? I noticed that is has not as of version 10606
tsramkumar
Member
106 Points
27 Posts
Re: Getting Calender to close on date selection
Aug 18, 2007 12:37 AM|LINK
I am having troubles getting this to work with Mozilla. If I add the OnClientDateSelectionChanged to the extender, the calendar stops showing up. Has any body experienced this? Or am I doing something wrong? I am having the exact functions mentioned in the above posts!
tsramkumar
Member
106 Points
27 Posts
Re: Getting Calender to close on date selection
Aug 18, 2007 01:06 AM|LINK
Also, it works fine in Mozilla if I add those 2 lines in the control's source (CalendarBehavior.js). Am I missing anything using the RegisterclientScriptblock solution?
ddalie
Member
2 Points
1 Post
Re: Getting Calender to close on date selection
Sep 09, 2007 02:43 AM|LINK
Guys, there's not need for registering client scripts or anything like that...
Just setting up the following will do the job:OnClientDateSelectionChanged
="focus"That will simply will execute "window.focus();" and that will make the calendar control to close in a clean way...
"AJAX Toolkit" "CalendarExtender"
cruentus
Member
40 Points
21 Posts
Re: Getting Calender to close on date selection
Sep 09, 2007 02:59 AM|LINK
Oh, that's sweet!
Yet, it's something you'll have to do in every calendar extender you have...
But good solution at all! ;)
Web Developer
ASP.NET / C# / (X)HTML / CSS / JavaScript
http://rafasoares.wordpress.com
(sorry, blog is just in portuguese... english site coming soon! ;] )