Saturday, March 24, 2012

Condition UpdatePanel being refreshed by asp:calendar postback

Hya,

I'm not sure the subject is appropriate but it's what i feel it's happening... I have a server control on UpdatePanel1 that pages a repeater, it his based on this article http://www.codeproject.com/aspnet/CollectionPager.asp although i made a few changes, now it inherits from a compositecontrol, and instead of prerendering the control it Creates Child Controls.


Ok now to the real issue, I have a popup calendar using the PopupControlExtender (having a few problems with the calendar from the toolkit http://forums.asp.net/thread/1547286.aspx) the calendar is inside a conditional updatepanel when the calendar postbacks the collectionpager in the other updatepanel is also refreshed!?!? e.g. it is initialized again and runs the createchildcontrols... Is this expected behaviour or am i doing something wrong?


this is the page code

<asp:Label ID="lblStartDate" runat="server" AssociatedControlID="start_date" Text="Start Date:"></asp:Label><br /> <asp:TextBox ID="start_date" runat="server" CssClass="frm_textbox" Width="150px" ValidationGroup="SearchLatestEvents"></asp:TextBox> <br /> <asp:Panel ID="PanelDatePicker" runat="server"> <asp:UpdatePanel ID="UpdatePanelDatePicker" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="CalendarDatePicker" SkinID="DatePickerSkin" runat="server" Width="160px" OnSelectionChanged="CalendarDatePicker_SelectionChanged"></asp:Calendar> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <ajaxToolkit:PopupControlExtender ID="PopupControlDatePicker" TargetControlID="start_date" runat="server" PopupControlID="PanelDatePicker" Position="Bottom" /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table border="1" cellpadding="3" cellspacing="0"> <tr> <th> Header1</th> <th> Header2</th> <th> Header3</th> <th> Header4</th> <th> Header5</th> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "Column1")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column2")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column3")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column4")%> </td> <td><%# DataBinder.Eval(Container.DataItem, "Column5")%> </td> </tr> </ItemTemplate> <FooterTemplate> </TABLE> </FooterTemplate> </asp:Repeater> <lo9ik:CollectionPager ID="CollectionPager1" runat="server" OnClick="CollectionPager1_Click" PagingMode="PostBack" /> </ContentTemplate> </asp:UpdatePanel>

The repeater is being populated by some random data

I can provide the collectionpager code if you wish. But even reverting to the original version the problem persists so i don't think it's the changes i've done to it.

What's odder about all this is that it only happens when the calendar postbacks! could it be that AJAX is not detecting it's postbacks and is refreshing all the updatepanels??

Your help would be much appreciated...

regards,

Even simpler example:

 <asp:TextBox ID="start_date" runat="server" CssClass="frm_textbox" Width="150px" ValidationGroup="SearchLatestEvents"></asp:TextBox> <br /> <asp:Panel ID="PanelDatePicker" runat="server"> <asp:UpdatePanel ID="UpdatePanelDatePicker" ChildrenAsTriggers="true" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="CalendarDatePicker" SkinID="DatePickerSkin" runat="server" Width="160px" OnSelectionChanged="CalendarDatePicker_SelectionChanged"></asp:Calendar> </ContentTemplate> </asp:UpdatePanel> </asp:Panel> <ajaxToolkit:PopupControlExtender ID="PopupControlDatePicker" TargetControlID="start_date" runat="server" PopupControlID="PanelDatePicker" Position="Bottom" /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> This panel should not be updated on date select!... <asp:UpdateProgress ID="UpdateProgress1" runat="server"> <ProgressTemplate> Updating... </ProgressTemplate> </asp:UpdateProgress> </ContentTemplate> </asp:UpdatePanel>

Code Behind:

protected void CalendarDatePicker_SelectionChanged(object sender, EventArgs e) { System.Threading.Thread.Sleep(3000); PopupControlDatePicker.Commit(CalendarDatePicker.SelectedDate.ToString("dd MMM yyyy")); }

Could please someone explain me what am i doing wrong? I have no triggers setup on UpdatePanel1, there's no reason for it to be updated when the calendar postback!!...

On my machine, UpdatePanel1 isnotbeing updated. I think you're being confused by the fact that your UpdateProgress control is showing. You probably want to put AssociatedUpdatePanelID="Update1" on it so that it only shows up when UpdatePanel1 is generating an async postback. Right now, since it's not associated with any particular UpdatePanel, it shows up on any async postback, so that's why you're seeing it appear.


Hi Steve,

Thanks for your contribution, I indeed realized that is true, but using the first example, my server control (collectionpager) still gets "refreshed"!... And that is actually what is causing the problems... On every createchildcontrols it goes through the pageddataset and adds the links/buttons for the functionality, because it is being "refreshed" and the dataset is not being databound it causes exceptions. I don't want to have to rebind the dataset everytime the calendar is used!..

I hope this makes things a bit clearer, if you want i can send you a full working example...


Kind Regards,


Maybe I understand... remember that when you use an UpdatePanel, there's an entire postback on the server. Try removing the UpdatePanels and get it to work that way first. From your last description, it sounds like your page won't work using regular postbacks, which means it also won't work when using async postbacks.


Spot on Steve, it was the way the control was built, it was databinding the repeater on it's onprerender method, causing it to create expections because the dataset was empty after a postback, i ended up removing the databind from within the control and instead use it to page the dataset and display the navigation...

So this means that all controls are in reality rendered again even if the postback is not for it's updatepanel!... It's slightly confusing as i expected that only the updatepanel to be updated should be "refreshed"...

Thanks for your help...


Glad you got it figured out!

Yup, during an async postback, the entire page gets rendered on the server, but only the part inside the UpdatePanel comes back down to the client.


Okay... so now we knowwhy it is happening. But is there any way to stop it happening? I have exactly the same issue.

It would be nice if there was some seperation and control over what UpdatePanels caused what UpdateProgresses to fire in the case where UpdatePanels are nested.

Or, a property on an UpdatePanel which simply says 'TriggerUpdateProgress' which can be set to false.

No comments:

Post a Comment