0

Here's the scenario:

I have a repeater inside an UpdatePanel called updPanel.

Inside this repeater I have two Buttons, which fire an ItemCommand.

In the page load I have this method:

if (!IsPostBack)
{               
    Bind();
}

Then, on Bind():

public void Bind()
{
    rptList.DataSource = Model.GetData(Version);
    rptList.DataBind();
}

Then, on ItemCommand event:

public void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
    //Some code to get info about the DataItems
    if (e.CommandName.Equals("MyCommandName1"))
    {
        //Do Stuff
    }
    else if (e.CommandName.Equals("MyCommandName2"))
    {
        //Do Other Stuff
    }
    Bind();
}

I have a button (inside the same update panel, but outside the repeater) which does nothing but Bind().

When I click an ItemCommand, the command executes, but the screen is not updated (One of the item buttons should change its icon after clicking). If I refresh the page, or click the "Bind" button, the repeater shows the data as expected.

Why isn't it binding after ItemCommand?

Thanks in advance!

EDIT: My Repeater:

<asp:Repeater ID="rptList" runat="server">
    <HeaderTemplate>
        <h3>
            <b class="rollback">Rollback</b> | <b class="emteste">Em Teste</b> | <b class="aindanaoincluido">
                            Ainda não Incluído</b> | <b class="parcialmenteok">Atividade Parcialmente OK</b>
                        | <b class="todosok">Atividade OK em Todas as Lojas</b> | <b class="publicado">Atividade
                            Publicada</b>
        </h3>
    </HeaderTemplate>
    <ItemTemplate>
        <div class="item" style="display: inline-block">
            <p style="font-size: 12px">
                <asp:ImageButton ToolTip="Marcar como Rollback" ImageUrl="/_layouts/Extensions/Versioning/img/rollback.png"
                                CommandName="MarkAsRollback" ID="btnItemRollback" CssClass="itembutton" runat="server" />
                <asp:ImageButton ToolTip="Esta atividade possui código. Clique para sinalizar como apenas procedure/config"
                                ImageUrl="/_layouts/Extensions/Versioning/img/code.png" CommandName="MarkAsProc"
                                ID="btnItemProc" CssClass="itembutton" runat="server" />
                 <asp:Image ToolTip="Esta atividade não possui scripts de banco/zips." ImageUrl="/_layouts/Extensions/Versioning/img/noscript.png"
                                runat="server" CssClass="itembutton" ID="btnItemScript" />
                 <asp:Label ID="labelWI" Text="" runat="server"></asp:Label>
                 <span style="color: #4A82CB">
                                <%# DataBinder.Eval(Container.DataItem, "SystemAssignedTo") %>
                                - </span><span style="color: Navy">
                                    <%# DataBinder.Eval(Container.DataItem, "SystemTitle") %>
                                </span>
                 <asp:HiddenField ID="workItemID" runat="server" />
              </p>
         </div>
         <hr class="item" noshade style="color: #4CBDCB; height: 2px; background-color: #4CBDCB" />
     </ItemTemplate>
</asp:Repeater>

EDIT: To simplify, this is the behavior i'm getting:

Clicking on a button outside the repeater: Icon changes. DB Updates.

Clicking on a button inside an item in the repeater: Icon doesn't change. DB Updates.

Clicking again on a button inside an item in the repeater: Icon changes. DB Updates. But now the corresponding item is wrong because I already changed the flag again

It seems to have to do with the order in which things happen.

EDIT: I forgot to mention, I tested with a full postback and everything works ok.

Conrad Clark
  • 4,533
  • 5
  • 45
  • 70

2 Answers2

0

Question for you - what changes are you making that you expect to see after clicking your item button? Are you updating the button control in the repeater or making a change to the datasource?

I suspect that your control is being rebound but you don't see any changes because you're overwriting the button that you've changed. Set some breakpoints or logging messages in your code (don't use response.write with ASP.Net AJAX, though - it will break things in async postbacks) and see what's actually happening. Is the bind() method being executed?

Brian Beckett
  • 4,742
  • 6
  • 33
  • 52
  • I'm changing the datasource. In the binding, I check a boolean field: if it's true, I set one specific icon. Else, i set another icon. – Conrad Clark Jul 14 '11 at 14:41
  • Ok... have you checked it in the debugger yet? Are you sure that the datasource is actually being updated? – Brian Beckett Jul 14 '11 at 15:08
  • Yes it is. I cannot debug right now because I need some firewall rules to remote debug the sharepoint server, but I tested binding to an empty list after clicking the item button, and voila, the list is empty. – Conrad Clark Jul 14 '11 at 17:07
0

When are you loading myDataSource?

If you're loading data into it in Page_Load, which is executed before rptList_ItemCommand, then bind() would be binding an old set of data to the repeater. This would explain your third summary point:

Clicking again on a button inside an item in the repeater: Icon changes. DB Updates. But now the corresponding item is wrong because I already changed the flag again

Can you give us more details about your datasource and the event handler for the button outside the repeater?

Brian Beckett
  • 4,742
  • 6
  • 33
  • 52
  • Hmm sorry if I accidentally made it unclear, but `myDataSource` is actually a method, specifically `Model.GetData(Version)`. `Version` is a property which I get through query strings. The `GetData` gets the data from a wcf service. The event handler for the button outside the repeater does the exact same thing as the button inside the repeater. – Conrad Clark Jul 14 '11 at 18:03
  • What was the problem, in the end? – Brian Beckett Jul 27 '11 at 19:41
  • I placed rptList.ItemCommand event in the wrong place, it seems. It's all working now. – Conrad Clark Jul 28 '11 at 14:55
  • Easily done :) I'm glad you were able to get it working in the end! – Brian Beckett Jul 28 '11 at 15:33