开发者

ASP.net - LinkButtons in a Repeater within an UpdatePanel are not triggering a postback of any kind

My page contains a Repeater that is loaded with data asynchronously as the data becomes available, using an UpdatePanel to manage the asynchronous requests.

The page contains something a little like this:

 <asp:UpdatePanel ID="DataUpdatePanel" runat="server">
 <ContentTemplate>
 <table>
    <asp:Repeater ID="RepeaterB开发者_StackOverflow社区lock" runat="server">
    <HeaderTemplate><thead><tr><th>Name</th><th>Status</th><th class="empty"></th></tr></thead></HeaderTemplate>
    <ItemTemplate><tr>
        <td><a class="link" href="Detail.aspx?item=<%# DataBinder.Eval( Container.DataItem, "Name") %>"><%# DataBinder.Eval( Container.DataItem, "Name") %></a>
        </td>
        <td><%# DataBinder.Eval( Container.DataItem, "Status") %></td>
        <td class="no-border">
            [<asp:LinkButton CommandName='Schedule' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Name") %>' ID="ScheduleButton" runat="server" CausesValidation="false" >Schedule</asp:LinkButton>]
        </td>
     </tr></ItemTemplate>
    </asp:Repeater>
</table>
</ContentTemplate>
</asp:UpdatePanel>

The problem being that the LinkButton does not appear to trigger a postback of any kind- there is no visible response to clicking on it and putting a break point on the event listener in the codebehind, it is never triggered.

I have tried manually adding a Trigger like this:

<Triggers>
   <asp:AsyncPostBackTrigger ControlID="ScheduleButton" />
</Triggers>

But unfortunately becausee the controls are within the ContentTemplate it crashes out if I try to do that.

Another avenue I have explored is to explicitly add them in the codebehind:

  RepeatData.DataBind();
  RepeatData.ItemCommand += new RepeaterCommandEventHandler(RepeatData_ItemCommand);

  UpdateScripts.RegisterAsyncPostBackControl(FindControlRecursive( RepeatData, "SchedulButton"));

The FindControlRecursive method just behaves like FindControl only it actually finds controls.

That doesn't crash out, but it also doesn't cause the LinkButtons to become effective.

Can anyone suggest what I need to do to cause them to post back as I expect them to?

Edit: Originally I had this page working without the UpdatePanel and it worked fine, with more data it started timing out, so I needed to obtain the data asynchronously. It was when I made this change that the linkbuttons ceased working.


You need to register all your link buttons to OnCommand with a server side event handler to use the CommandName / CommandArg properties.

[<asp:LinkButton CommandName='Schedule' CommandArgument='<%# DataBinder.Eval(Container.DataItem, "Name") %>' ID="ScheduleButton" runat="server" CausesValidation="false" OnCommand="LinkButtonCommandEventHandler" >Schedule</asp:LinkButton>]

See msdn reference:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linkbutton.commandname.aspx


You need either <asp:Repeater ID="RepeaterBlock" runat="server" OnItemCommand="RepeaterData_ItemCommand">

or RepeatData.ItemCommand += new RepeaterCommandEventHandler(RepeatData_ItemCommand); in each postback before RepeatData.DataBind();

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜