Showing posts with label selects. Show all posts
Showing posts with label selects. Show all posts

Saturday, March 24, 2012

CalendarExtender: Anyway to AutoPostBack?

I'd like to cause a post back when a user selects a date using the CalendarExtender. Anyway to do this?

You could try this...

1) Add the following code to your page's OnLoad event - this basically registers a function to handle the calendar date selection change on the client and force a postback (sorry if you're a C# person)

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadConst strKeyAs String ="calendarExtenderPostback"If Not Me.ClientScript.IsClientScriptBlockRegistered(Me.GetType(), strKey)Then Dim pboAs PostBackOptions =New PostBackOptions(Me) pbo.AutoPostBack =True pbo.RequiresJavaScriptProtocol =False pbo.PerformValidation =True Dim strScriptAs String =String.Format("function calendarExtenderPostback(e) {{ {0} }}",Me.ClientScript.GetPostBackEventReference(pbo).ToString)Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), strKey, strScript,True)End If End Sub

2) Add the following markup to your page to create the script manager, textbox and calendar extender... NB the use of OnClientDateSelectionChanged

<asp:ScriptManagerID="ScriptManager1"runat="server"></asp:ScriptManager>

<asp:TextBoxID="DateTextBox"runat="server"/>

<ajaxToolkit:CalendarExtenderID="CalendarExtender1"runat="server"TargetControlID="DateTextBox"Format="dd MMM yyyy"OnClientDateSelectionChanged="calendarExtenderPostback"/>


This works...to a point. It causes a postback, but not one that UpdatePanels seem to recognize. When I cause a postback using a button the content on my page in updatepanel's correctly updates. When I use the CalendarExtender autopostback method you described, the whole page refreshes. Any ideas?


There are quite a few posts on these forums for forcing an UpdatePanel to postback... it doesn't look like there currently a "correct" method of doing this (e.g. UpdatePanel.Update()) - though I might be wrong...

Suggestions include having a hidden button (using style="display: none") in your UpdatePanel which triggers the update.

You can then force the Click event for this in the code I described above (instead of the postback code)... which will in turn force the UpdatePanel to update!

This post may help...http://forums.asp.net/thread/1426873.aspx

Hope this makes sense!

Wednesday, March 21, 2012

CalendarExtender, want only current month date visible

hi all,

I have a problem, I want to display days of only current month or whichever month a user selects. I mean by default calendar extender shows all dates , even if we have selected November, it will show some days of previous month and some days of next month along with current month's dates. I only want to display current month's dates.

I applied css specified in http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Calendar/Calendar.aspx

but that's changing color of each day. I was thinking by using css somehow i will hide previous and next month days, but of not avail.

please suggest,

thanks...

Hi Forums_user,

As far as I know, it is not supported now unless you modify its source code. CalendarExtender generate all the days , months and years on the client, you can find it in its source code with the name _buildDays,_buildMonths and _buildYears.

I hope this help

Best regards,

Jonathan

CalendarExtender Question

I was wonering if there is a way to fire a javaScript function after the user selects a date. Kind of like in the ModelPopup where we can set the onOkScript property except this would be like an OnDateChangedScript property...is there an easy way to do this with the CalendarExtender? Basically the date would already be updated on the screen and I want to call this javaScript function to send the new date back to the data base via JavaScript/WebService...Any thoughts?

Thanks, Greg

That is what the onClientDateSelectionChanged method is for!!...nevermind.

I have an example as to how to fire a javaScript event after the user select a different date...you can see the code here:http://forums.asp.net/thread/1627224.aspx