Saturday, March 24, 2012

working AJAX with a paging user control

Hi,

I am currently working with embedding AJAX into a previously developed website, and until now have had no issues, what i am trying to do i am not sure is possible, let me explain...

I have a simple web form which contains a repeater, and a user control (which is used for paging "ucPaging"), this user control has a dropdownlist embedded in it. I want the drop down list to fire an AsyncPostBackTrigger to the upnlPlayers update panel, and the repeater to use the SelectedValue of the dropdownlist in the paging user control.


I have tried to create a new AsyncPostBackTrigger in the code behind of the main aspx page, but at runtime, it says that the dropdownlist does not exist. Is what i am trying to do possible? I really don't want to have to resort to using the ASP paging control that is provided, as i am potentially returning hundreds of thousands of records.

Provided is the code in the main Players.aspx page...


<controls:Paging ID="ucPaging" runat="server" />
<ajax:UpdatePanel ID="upnlPlayers" runat="server">
<ContentTemplate>
<asp:Repeater ID="repPlayers" runat="server" OnItemDataBound="repPlayers_OnItemDataBound"....... etc etc etc you know the deal

</ContentTemplate>
<Triggers>
<ajax:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
</Triggers>
</ajax:UpdatePanel>

And the user control code...

<div id="Paging">
<div class="Previous"><asp:HyperLink ID="hlPrevious" runat="server" /></div>
<div class="Page"><asp:Label ID="lblViewingRecords" runat="server" /> <asp:DropDownList ID="ddlRecords" runat="server" OnSelectedIndexChanged="ddlRecords_OnSelectedIndexChanged" AutoPostBack="true" /></div>
<div class="Next"><asp:HyperLink ID="hlNext" runat="server" /></div>
</div>

Thanks for your help!

e

Since the DropdownList is in User Control, You have to add it as programmatically rather than declaratively. For Example in the Page load event add the following codes:


if (!IsPostBack)
{
AsyncPostBackTrigger tr = new AsyncPostBackTrigger();

tr.ControlID = YourDropDownList.ClientID;
tr.EventName = "SelectedIndexChanged";
YourUpdatePanel.Triggers.Add(tr);
}

No comments:

Post a Comment