tags:

views:

27

answers:

2

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="RepeaterBlock" 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.

+1  A: 

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

asawyer
I'm using the ItemCommand for the Repeater as a whole rather than working on a button by button basis: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx
glenatron
Gotcha, does your Page_Load event get hit on the link button clicks? Does it change anything if you register the OnCommand event, THEN databind?
asawyer
No difference changing the order of binding. It seems that the linkbuttons are just doing nothing when I click them. I guess the next step may be stepping through the JavaScript but even if I find the cause of the problem there, I'm not sure how I'll adjust it.
glenatron
Page_Load isnt being hit then?
asawyer
Ah, Page_Load was being hit, but I was only initialising the event handler if it wasn't a postback. Apparently that worked ok when it was synchronous, but not any more. You don't have to reinitialise the data in the repeater but you do have to add event handlers again. Way to be consistent, Microsoft.
glenatron
It's not microsofts fault :) http is stateless after all.
asawyer
A: 

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();

Musa Hafalır
I tried changing the order of the code above ( you'll have noticed that I have the second line in my last snippet above ) to put the eventhandler before the databind and it made no difference.
glenatron