开发者

Can't get to rebind a Repeater after firing ItemCommand (using asyncpostback via updatepanel)

开发者 https://www.devze.com 2023-03-20 13:07 出处:网络
Here\'s the scenario: I have a repeater inside an UpdatePanel called updPanel. Inside this repeater I have two Buttons, which fire an ItemCommand.

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.Data开发者_JS百科Source = 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.


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?


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?

0

精彩评论

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

关注公众号