How to do AsyncPostBackTrigger for the LinkButton in the Repeater

孤人 提交于 2019-11-27 18:36:29

Inside ItemCreated event of the Repeater control register the button with ScriptManager.

//Inside ItemCreatedEvent
ScriptManager scriptMan = ScriptManager.GetCurrent(this);
LinkButton btn = e.Item.FindControl("order_button") as LinkButton;
if(btn != null)
{
    btn.Click += LinkButton1_Click;
    scriptMan.RegisterAsyncPostBackControl(btn);
}

I had similar problem, but I didn't want to update the whole repeater, only a content outside of the repeater... so what I did was

1. Add the repeater

<asp:Repeater ID="productList" runat="server">
  <!-- my repeater -->
<asp:Repeater>

2. Add the Update Panel with the updatable content, and the trigger

<asp:UpdatePanel ID="up" runat="server">
    <ContentTemplate>
        <!-- when the click on repeater's links, this content will be updated -->
    </ContentTemplate>
    <Triggers>
        <!-- trigger will be the repeater's links/btn that generate postback -->
        <asp:AsyncPostBackTrigger ControlID="productList" />
    </Triggers>
</asp:UpdatePanel>

Adding the following attribute to the page directive containing the repeater and linkbutton will also work:

<%@ page ClientIDMode="AutoID" %>

I had a control that needed to work both asynchronously and full postback, so using the ScriptManager.RegisterAsyncPostBackControl would not work for me. By enclosing the control (which contained a repeater and linkbutton) inside of an UpdatePanel, the linkbutton would cause an asynchronous postback. With no updatepanel, the linkbutton would cause a fullpostback.

Hope this helps someone else.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!