Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Very, Very slow clearing a list box

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Erik - 29 Oct 2007 21:48 GMT
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>
Peter Bucher [MVP] - 30 Oct 2007 10:47 GMT
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?

Signature

Gruss, Peter Bucher
Microsoft MVP - Visual Developer ASP / ASP.NET, Switzerland
http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
http://www.aspnetzone.de/blogs/peterbucher/ - Auf den Spuren von .NET

Patrice - 30 Oct 2007 11:57 GMT
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 ?

--
Patrice

> Hi Everyone,
>
[quoted text clipped - 69 lines]
>
> </html>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.