Solved

Webpage is working unusually slow

Posted on 2012-03-13
7
311 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
7 Comments
 
LVL 35

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Loop not working 29 47
Runtime Error 2 28
scanning dentists xray (the small ones) 3 45
C# MVC and a global static factory that never dies 4 48
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now