The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

Slow Page Loading

With VB.NET, I’m using server-side code to dynamically add rows to a Table web control. (Complete code listing below.) This is the loop I use to add the rows:


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For i As Int32 = 1 To 5000
            Dim tr As New TableRow

            Dim td0 As New TableCell
            td0.Text = "Column 0"
            tr.Cells.Add(td0)

            Dim td1 As New TableCell
            td1.Text = "Column 1"
            tr.Cells.Add(td1)

            Dim td2 As New TableCell
            td2.Text = "Column 2"
            tr.Cells.Add(td2)

            tr.Attributes.Add("onmouseover", "javascript: this.style.backgroundColor='Yellow';")
            tr.Attributes.Add("onmouseout", "javascript: this.style.backgroundColor='';")

            tblMain.Rows.Add(tr)
        Next
    End Sub


If I comment out these two lines:
            tr.Attributes.Add("onmouseover", "javascript: this.style.backgroundColor='Yellow';")
            tr.Attributes.Add("onmouseout", "javascript: this.style.backgroundColor='';")

The page loads in about 10 seconds. With those lines executing, the page takes over five minutes to load. Has anyone dealt with this? Can anyone suggest a work around?





Server Code

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected tblMain As Table

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        For i As Int32 = 1 To 5000
            Dim tr As New TableRow

            Dim td0 As New TableCell
            td0.Text = "Column 0"
            tr.Cells.Add(td0)

            Dim td1 As New TableCell
            td1.Text = "Column 1"
            tr.Cells.Add(td1)

            Dim td2 As New TableCell
            td2.Text = "Column 2"
            tr.Cells.Add(td2)

            tr.Attributes.Add("onmouseover", "javascript: this.style.backgroundColor='Yellow';")
            tr.Attributes.Add("onmouseout", "javascript: this.style.backgroundColor='';")

            tblMain.Rows.Add(tr)
        Next
    End Sub

End Class

Page Code

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Speed.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>WebForm1</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">

    <form id="Form1" method="post" runat="server">
   
        <asp:Table ID="tblMain" Runat="server"></asp:Table>

    </form>

  </body>
</html>
Jeff Collins Send private email
Thursday, December 15, 2005
 
 
Renders on my machine in a second or so with the mouseovers using IE. Maybe something with your setup.
GROK!
Thursday, December 15, 2005
 
 
Thanks. I am developing on a 1.4 gig machine, and it does run faster on our server. Still, it should run faster. I have narrowed it down to something going on in either the PreRender or Render events.
Jeff Collins Send private email
Thursday, December 15, 2005
 
 
Are you seeing this the first time you view the page, or the second time?  Don't forget about the dynamic assembly compilation that ASP.NET does on the 1st page view.

BTW, this should be in the .NET questions area.
example Send private email
Friday, December 16, 2005
 
 
A couple of things:

First, the obvious question is why would you want a table with 5000 rows to display in a browser?  Perhaps a datagrid with paging is another solution?

Second, assuming you have to do #1, is page caching an option?  If the data that makes up the page is fairly static, you could of course cache it and it would be in memory and display quickly, except of course when the cache gets invalidated.
Mike Stephenson Send private email
Friday, December 16, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz