Container control managing list of LinkButtons, trouble with delet

  • Thread starter Thread starter Mark
  • Start date Start date
M

Mark

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
 
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 (e-mail address removed) 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:
(e-mail address removed).

==================================================
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.
 
Hi Mark,

Have you sent the demo to me?

Regards,
Allen Chen
Microsoft Online Community Support
 
Back
Top