views:

105

answers:

1

Hey,

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 "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

A: 

While debugging I noticed the controls in the method "OnRateClick" are empty and don't contain the right values.

Sorry, but could you elaborate more about this?

Gan
amm, it's being a while... as far as I remember the controls were all null, or had all null properties.
yellowblood
It's quite difficult without looking at your actual full code. Perhaps you need to use some other way to debug it. Have you tried remove the update panel and see if the coding works correctly with full page postback?
Gan