Container control managing list of LinkButtons, trouble with delet

Discussion in 'ASP .Net' started by Mark, Jan 16, 2009.

  1. Mark

    Mark Guest

    Hi...

    I inherited an app that has a control for managing a variable list of
    objects. On the page the list gets rendered with LinkButtons next to each
    saying "Remove". All of the LinkButtons have id="remove_1", id="remove_2"
    and so on.

    Just noticed an interesting bug today. If you click remove_1, the postback
    happens, the LinkButton's Click event fires and the first element gets
    deleted.

    When the resulting page is rendered what *was* remove_2 is now remove_1
    (since the container control re-constructs the remaining list).

    If I click the new remove_1 (former remove_2), the postback happens, all the
    controls get instantiated but remove_1's Click event *does not fire*. It
    just builds and renders the page again. If I click the LinkButton again,
    then it does finally delete the entry.

    It seems like there's some kind of state confusion stemming from re-using
    the id "remove_1" - like it remembers the last one having been clicked and
    therefore doesn't need to click again. But looking at the LinkButton class,
    I don't see any state member that I could try to reset.

    Where would I be able to clear the memory of the deleted member's having
    been clicked?

    Thanks
    Mark
     
    Mark, Jan 16, 2009
    #1
    1. Advertising

  2. Hi Mark,

    I think code is needed for us to troubleshoot this issue. My action plan
    is, I can provide a working code for you to compare with your current code
    on your side to see what the difference is and you can provide me a demo
    that can reproduce this problem to let me test on my side. In this way we
    can come up with a solution quickly.

    Here's my code. I use ViewState to store the datasource and use Repeater to
    render the data.

    Aspx:

    <asp:Repeater ID="Repeater1" runat="server"
    onitemcommand="Repeater1_ItemCommand">
    <ItemTemplate>
    <%#Container.DataItem %>
    <asp:LinkButton ID="LinkButton1" runat="server"
    CommandArgument='<%#Container.DataItem %>'
    CommandName="Delete">Remove</asp:LinkButton>
    <br />
    </ItemTemplate>
    </asp:Repeater>

    Aspx.cs:

    public partial class _Default : System.Web.UI.Page
    {
    List<int> list;
    protected void Page_Load(object sender, EventArgs e)
    {
    list = ViewState["data"] as List<int>;
    if (list == null)
    {
    list = new List<int>();
    for (int i = 0; i < 10; i++)
    {
    list.Add(i);
    }
    ViewState["data"] = list;
    }
    this.Repeater1.DataSource = list;
    if (!IsPostBack)
    {
    this.Repeater1.DataBind();
    }
    }

    protected void Repeater1_ItemCommand(object source,
    RepeaterCommandEventArgs e)
    {
    if (e.CommandName == "Delete")
    {
    list.Remove(Convert.ToInt32(e.CommandArgument));
    this.Repeater1.DataSource = list;
    this.Repeater1.DataBind();
    ViewState["data"] = list;
    }
    }
    }

    My email is se update here after sending the
    project in case I missed that email.

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Allen Chen [MSFT], Jan 19, 2009
    #2
    1. Advertising

  3. Hi Mark,

    Have you sent the demo to me?

    Regards,
    Allen Chen
    Microsoft Online Community Support
     
    Allen Chen [MSFT], Jan 21, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFqZWs=?=

    LinkButtons within Repeater control

    =?Utf-8?B?TWFqZWs=?=, Nov 11, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    454
    Scott Allen
    Nov 11, 2004
  2. news.rcn.com
    Replies:
    1
    Views:
    8,376
    andrewh1
    Jul 3, 2004
  3. jacob navia
    Replies:
    5
    Views:
    526
    jacob navia
    Sep 28, 2009
  4. Jan Limpens

    How can I use working Linkbuttons within a Web Custom Control?

    Jan Limpens, Oct 14, 2003, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    181
    John Saunders
    Oct 14, 2003
  5. Spanky
    Replies:
    2
    Views:
    130
    Spanky
    Sep 7, 2003
Loading...

Share This Page