开发者

Repeater Item command creating post back with Update Panel

开发者 https://www.devze.com 2023-03-25 15:03 出处:网络
I have update panel in that I have repeater control with linkbutton which are having command property

I have update panel in that I have repeater control with linkbutton which are having command property

I have tried both ItemCommand event or link button click both are creating postbacks

Here the code for that

<asp:UpdatePanel ID="upFC" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
        <ContentTemplate>
     <asp:Repeater ID="rptFCItem" runat="server" OnItemDataBound="rptFCItem_ItemDataBound" OnItemCommand="rptFCItem_ItemCommand" EnableViewState="true">
                    <ItemTemplate>
                        开发者_StackOverflow<asp:LinkButton ID="lnkElement" runat="server" OnClick="lnkCurrent_Click" CommandName="Element"></asp:LinkButton>
                    </ItemTemplate>
                </asp:Repeater>
    </ContentTemplate>

and following is server side code

  protected void lnkCurrent_Click(object sender, EventArgs e)
    {
        BindFC(Element, true);
    }


 protected void rptFCItem_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemIndex >= 0)
        {
            LinkButton lnkElement = (LinkButton)e.Item.FindControl("lnkElement");
            if (lnkElement != null)
            {
                lnkElement.Text = (e.Item.ItemIndex+1).ToString();
            }
        }
    }

protected void rptFCItem_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
       //some code here
    }

But neither itemcommand work or click event works with update panel async its creating full postback.

Does any one have solution for it.

Best Regards,

Jalpesh


In the code posted above you have registered the event in Markup as OnItemCommand="rptFlashCardItem_ItemCommand"

In the code behind, the name differs as 'rptFCItem_ItemCommand'. Does this existing code give you an error at compile time? If yes, it could be a name mismatch.


If you swap out the Repeater for a ListView it works.

<asp:UpdatePanel ID="upFC" runat="server" UpdateMode="Always" ChildrenAsTriggers="true">
        <ContentTemplate>
            <asp:ListView ID="rptFCItem" runat="server" OnItemDataBound="rptFCItem_ItemDataBound"
                OnItemCommand="rptFCItem_ItemCommand" EnableViewState="true">
                    <ItemTemplate>
                    <asp:LinkButton ID="lnkElement" runat="server" OnClick="lnkCurrent_Click" CommandName="Element"></asp:LinkButton>
                </ItemTemplate>
            </asp:ListView>
        </ContentTemplate>
    </asp:UpdatePanel>

You'll also need to replace the repeater event args with the ListView versions.

protected void rptFCItem_ItemDataBound(object sender, ListViewItemEventArgs e)
{
    if (e.Item.DataItemIndex >= 0)
    {
        LinkButton lnkElement = (LinkButton)e.Item.FindControl("lnkElement");
        if (lnkElement != null)
        {
            lnkElement.Text = (e.Item.DataItemIndex + 1).ToString();
        }
    }
}

protected void rptFCItem_ItemCommand(object source, ListViewCommandEventArgs e)
{
    // some code here
}

I think the reason it doesn't work with a repeater has to do with the fact that repeaters don't provide the same naming structure inside of them as the other list type controls.

0

精彩评论

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

关注公众号