Showing posts with label cause. Show all posts
Showing posts with label cause. 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 seems to cause loss of Session

I have a web app which passes a Session object between pages. When I added a CalendarExtender to the page, that Session object is null when I navigate to the next page, even if I never actually click on the associated ImageButton. The version number of the AjaxControlToolkit.dll is 1.0.10920, which I believe is the latest.

Any thoughts?

Thanks.

Dan

I noticed another post today about the CalendarExtender causing memory leaks in IE. Based on one of the suggestions in that thread, I tried my app in both IE7 & Firefox outside of VS. It exhibited the same problems as with IE inside VS.

Any suggestions would be greatly appreciated.

Thanks.

Dan


Hi Dhurwitz,

As we know, CalendarExtender works on the client and session works on the server side so it seems your issue is not caused by the CalendarExtender.

I suggest that we should use a discharging method. First remove the CalendarExtender from your page and have a test. Here is thedocument which shows how to resolve the session issues.

Best regards,

Jonathan