Aishwarya Shiva
Aishwarya Shiva

Reputation: 3406

Updatepanel inside repeater is unable to maintain state

I have a user-control that is loaded by a repeater that is using CollectionPager. This user-control has an UpdatePanel inside it as given below:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div style="float:right; height:32px; width:32px"><asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
            <ProgressTemplate>
                <img alt="Working..." class="auto-style5" src="Images/ajaxloader.gif" width="32px" height="32px" />
            </ProgressTemplate>
        </asp:UpdateProgress></div>
            <br />
            <div style="font-family:Segoe UI Light, Tahoma, Geneva, Verdana, sans-serif">
                Upvoted By
                <asp:Label ID="lblUp" runat="server" Text=""></asp:Label>
                &nbsp;| Downvoted By
                <asp:Label ID="lblDown" runat="server" Text=""></asp:Label>
                <br />
            <asp:LinkButton ID="lnkUp" runat="server" ForeColor="#003300" OnClick="lnkUp_Click">Vote Up</asp:LinkButton>
            &nbsp;
            <asp:LinkButton ID="lnkDown" runat="server" ForeColor="Red">Vote Down</asp:LinkButton>
            &nbsp;
            <asp:LinkButton ID="lnkAddComment" runat="server" ForeColor="Maroon">Add Comment</asp:LinkButton>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>

The LinkButton lnkUp increments the value of label lblUp by 1 as follows:

protected void lnkUp_Click(object sender, EventArgs e)
    {
        try
        {
            lblUp.Text = (int.Parse(lblUp.Text) + 1).ToString();
            lnkUp.Text = "Undo vote up";
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

The problem is that, when I click one user-control's lnkUp LinkButton loaded by the repeater it increments the value of corresponding lblUpLabel. But when I click another user-control's lnkUp LinkButton that is also loaded by the repeater, it successfully increments its corresponding lblUp lable text but resets the former user-control's lblUp label text. In short the UpdatePanels are not maintaining state when clicked on another user control. How do I solve this?

Upvotes: 1

Views: 180

Answers (1)

Mahesh
Mahesh

Reputation: 731

in updatepanal check out your update mode it should be 'always'. or do

protected void lnkUp_Click(object sender, EventArgs e)
    {
        try
        {
            lblUp.Text = (int.Parse(lblUp.Text) + 1).ToString();
            lnkUp.Text = "Undo vote up";
UpdatePanel1.update();
        }
        catch (Exception ex)
        {
            throw ex;
        }
}

Upvotes: 1

Related Questions