Solved

Webpage is working unusually slow

Posted on 2012-03-13
7
317 Views
Last Modified: 2012-04-09
I am working on a webpage in my web application. It is a fairly simple application with a datagrid which is populated from an Excel file and also from the database. The number of rows in the datagrid is in hundreds. I understand if it takes time to upload the rows. But after the datagrid is loaded, even a button click event is taking like 2 minutes. The button click event is just making a panel message box visible. How can I figure out what's taking so long?
0
Comment
Question by:Angel02
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 36

Assisted Solution

by:Miguel Oz
Miguel Oz earned 200 total points
ID: 37717345
If you are using VS2010, you can use the performance profiler:
http://msdn.microsoft.com/en-us/library/ms182372.aspx

Depending on your business rules, you should aim to interact with Excel as little as possible. For example loading Excel information into Session (if you do not need to interact/save results back)
Can you provide some sample code on how you are loading the datagrid?
0
 
LVL 9

Expert Comment

by:abhinayp86
ID: 37717428
in the datagrid, turnoff viewstate and c if the page is any faster.
Also make sure that u are binding the grid in "If not Page.IsPostBack" in page load
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37717696
Show us some code.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Angel02
ID: 37718429
I have attached code for my function BindGrid() which loads the Datagrid. I use a stored procedure to populate the datagrid.
I also have a ItemDataBound Event where I am assigning different colors to the rows depending on a column value. I have used similar code for ItemDataBound event in other webpages but they were not not slowed down.

- After the datagrid is loaded, any onclick event is taking for ever to complete. It looks like the whole page is refreshing, although the onclick event which just makes an asp:Panel visible is not supposed to refresh the page.
It is taking time to reload the page even if a button click just calls
Response.Write("<Script Language='JavaScript'>alert('Are you sure you want to continue?');</Script>")

- I made enableviewstate="false". The on click events worked super fast as expected. But after a button or checkbox click, the datagrid disappeared.

- I am not binding the datagrid in the pageload(). I have a "browse" button on my webpage which selects an Excel file and when I click "Upload", then the datagrid is loaded.
BindGrid.txt
ItemDataBound.txt
0
 
LVL 16

Expert Comment

by:Rose Babu
ID: 37718633
are you calling BindGrid() function for some other process in same page?

check the BindGrid occurrences.
0
 
LVL 9

Accepted Solution

by:
abhinayp86 earned 300 total points
ID: 37722618
I have a feeling that your BindGrid() is being called too many times during a normal postback.

If thats not the case and ur page is still slow, turnoff the viewstate for the grid, and use session to save and retrieve data. (Code below)

 
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       
	 If m_BrowseClick = 1 Then
            If Session("excelSP_data") Is Nothing Then 'Only true when session timesout
                BindGrid()
            Else
                MyDataGrid.DataSource = Session("excelSP_data")
                MyDataGrid.DataBind()
            End If
        End If
  End Sub

 Private Property m_BrowseClick () As Integer
        Get
            Try
                Return ViewState("browse_click")
            Catch ex As Exception
                Return 0
            End Try

        End Get
        Set(ByVal value As Integer)
            ViewState("browse_click") = value
        End Set
    End Property

Sub BindGrid()
        Dim mydataset As DataSet = New DataSet
        MyConnection = New SqlConnection(Conn)
        Dim MyAdapter As SqlDataAdapter
        Dim MyCommand As SqlCommand
        MyCommand = New SqlCommand("ExcelSP", MyConnection)
        MyCommand.CommandType = CommandType.StoredProcedure
        MyCommand.Parameters.Add("@ID", SqlDbType.Int).Value = CInt(Session("ID"))
        MyAdapter = New SqlDataAdapter(MyCommand)
        Try
            MyAdapter.Fill(mydataset, "ExcelList")
            
        Catch ex As Exception
            Throw (ex)
        End Try
        If mydataset.Tables(0).Rows.Count >= 1 Then
            m_BrowseClick = 1
            session("excelSP_data") = mydataset
            MyDataGrid.DataSource = mydataset
            MyDataGrid.DataBind()
        else
          m_BrowseClick = 0
        End If
        MyCommand.Dispose()
        MyAdapter.Dispose()
        mydataset.Dispose()
        MyConnection.Close()
    End Sub

Open in new window

0
 

Author Comment

by:Angel02
ID: 37722671
I traced for bindgrid occurrences. It is being called only once. The page is being loaded after every click but bindgrid() is not in page load.
I'll try the code to use the session and see.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question