开发者

How to make UpdatePanel inside ListView work?

I have a page with a listview that shows something like posts. On each post there should be a "rate box" which works similar to the "Like" button in facebook. The rate box is a User Control, that has an update panel inside it.

If I put the control with some random values in the page it works great - but when I put it inside the ListView, where it should be located, it won't work. The method is being called, but nothing happens.

I simplified the code a bit to make it easier to understand:

The "rate box" control:

    protected void OnRateClick(object sender, ImageClickEventArgs e)
    {
        Rate++;
        RateAmountLiteral.Text = Rate.ToString();
        RateButton.Visible = false;
        FeedbackLiteral.Visible = true;

        rateButtonPanel.Update();
    }

ascx:

<div class="rate_div">
    <asp:UpdatePanel ID="rateButtonPanel" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <fieldset>
                Rate:
                <asp:Literal ID="RateAmountLiteral" runat="server"></asp:Literal>
                <asp:ImageButton ID="RateButton" runat="server" ImageUrl="icn_rate.png"
                    OnClick="OnRateClick" />
                <asp:Literal ID="FeedbackLiteral" runat="server" Visible="false">Thanks for rating!</asp:Literal>
            </fieldset>
        </ContentTemplate>
    </asp:UpdatePanel>
</div>

aspx (using the control):

                     <asp:ListView ID="PostsView" runat="server" ItemPlaceholderID="itemPlaceHolder2"
                        <LayoutTemplate>
                            <div class="posts_div">
                                <asp:PlaceHolder ID="itemPlaceHolder2" runat="server" />
                            </div>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <div class="post_div">
                                <div class="post_body">
                                    <%# CurrentPost.Body %>
                                </div>
                                <UC:RatingBox id="RatingBox" runat="server" 
                                PostID="<%# CurrentPost.ID %>"
                                Rate="<%# CurrentPost.Rate %>"/>
                                By: <a href="<%# CurrentPost.Author.LinkToProfile %>">
                                    <%# CurrentPost.Author.DisplayName %>
                                </a>&nbsp;|&nbsp;
                                <%# CurrentPost.LiteralTime %>
                            </div>
                        </ItemTemplate>
                    </asp:ListView>

While debugging I noticed the controls in the method开发者_如何学C "OnRateClick" are empty and don't contain the right values. Please advice.

Also if you have any comments about the way I did things, don't hold yourself.

Thanks


There are a lot things that you may not have set up, I cannot tell from just the code snippet you have given. But make sure you do the following: -

1) Place a ScriptManager "" on the page.

If you are using master page in your application and your web page uses the master page, place script manager in master page. Or alternatively,you can also place script manager on specific web pages anyway.

2) Add a Triggers for the button RateButton in your Update panel.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜