Very, Very slow clearing a list box

E

Erik

Hi Everyone,

I'm not sure why this is happening but I need to populate a listbox with
about 10000 items and then at some point clear them again. Adding the items
is not a problem and it takes 2 or 3 seconds but when I try and clear them
it just hangs the browser at 100% cpu. The code I am testing with is below.
I have tried clearing the listbox client side as well and it is exactly the
same problem.

Any help would be appreciated

Thanks


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs"
Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void btnShowOrderDetails_Click(object sender, EventArgs e)
{
for (int i = 0; i < 10000; i++)
{
lst.Items.Add(new ListItem(i + " Testing Testing Testing",
i.ToString()));
}
}

protected void btnClearOrderDetails_Click(object sender, EventArgs e)
{
lst.Items.Clear();
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
</div>
<div>
<asp:Button ID="btnShowOrderDetails" runat="server"
OnClick="btnShowOrderDetails_Click" Text="Show Order Details" />
<br />
<asp:Button ID="btnClearOrderDetails" runat="server" Text="Clear
Order Details" OnClick="btnClearOrderDetails_Click" /><br />
<br />
<asp:UpdatePanel ID="UpdatePanel2" runat="server"
ChildrenAsTriggers="false" UpdateMode="conditional" EnableViewState="false">
<Triggers>
<asp:AsyncPostBackTrigger
ControlID="btnShowOrderDetails" EventName="Click" />
<asp:AsyncPostBackTrigger
ControlID="btnClearOrderDetails" EventName="Click" />
</Triggers>
<ContentTemplate>
<asp:ListBox id="lst" runat="server" Style="width:
300px; height: 100px;" EnableViewState="false" Rows="10"
SelectionMode="Multiple"></asp:ListBox>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>

</html>
 
P

Peter Bucher [MVP]

Hello Erik

I would say, this is too much.
Yes i know, that would not help you, but its possible the one and only
answer.

Even if you clear the items on the serverside, it has to be handled on
server- and clientside.
And i think thats too much for the clientside engine.

You tried that in different browsers?
 
P

Patrice

I would expect this client side as a naïve approach would refresh the
control with each change. By updating the list once, you should be able to
workaround this problem.

Removing those items server side is a bit more surprisingly slow (are you
sure this is where your time budget is spent or do you have also something
client side that could explain this) and I would have to test this.

As a side note this is really a high number. Can't you change the UI so that
the user can filter this instead of having to find something among all those
items ?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top