Monday, March 26, 2012

Updating control in UserControl inside of UpdatePanel

Hello,

I have a page that contains a UserControl. Most of the page (including the UserControl) is wrapped in an UpdatePanel. When an AJAX event on the page occurs, I'd like to call a method inside of the UserControl to update a label. Problem is, when I do this, the page adds a new copy of the UserControl's contents (with the updated label) at the bottom of the page rather than refreshing the existing copy. Any idea what I'm doing wrong?

Thanks.

Are you dynamically creating the controls in the user control or dynamically creating the usercontrol itself? Posting your source code would be helpful.


Nope, no dynamic loading of anything. The page just looks something like this:

<asp:ScriptManagerrunat="server"ID="ScriptManager1"></asp:ScriptManager>

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

<Custom:HotelDetailsrunat="server"ID="HotelDetails1"/>

</ContentTemplate>

</asp:UpdatePanel>

And there's an event in the code-behind of the page:

ProtectedSub DateChanged(ByVal srcAsObject,ByVal eAs Infragistics.WebUI.WebSchedule.WebDateChooser.WebDateChooserEventArgs)

HotelDetails1.UpdateRooms(wdcCheckIn.Value, wdcCheckOut.Value)

EndSub

And in the UserControl, there's a public method like this:

PublicSub UpdateRooms(ByVal StartDateAs DateTime,ByVal EndDateAs DateTime)

litName.Text = StartDate.ToShortDateString()

EndSub


I split the page into two UpdatePanels...one for the even firing controls and one for the UserControls that get updated and that seems to resolve the issue.

No comments:

Post a Comment