Showing posts with label autopostback. Show all posts
Showing posts with label autopostback. 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 with targetcontrol and autopostback

I just updated from build 10618 to 10920. I have two pages that use the calendarextender where the targetcontrol's autopostback property is set true. After appling the update both of these pages continue to postback has if the txtbox was changed.

Forget it... I hav searched all over the place and cannot find a solutions. I have calendarextender connected to textboxes wityh autopostback in a gridview... It does a postback on pageload for every single textbox so in case 10 rows in gridview, ten time the ontextchanged function during the first load...