Solved

Webpage is working unusually slow

Posted on 2012-03-13
7
307 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
Comment Utility
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
Comment Utility
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
Comment Utility
Show us some code.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:Angel02
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

15 Experts available now in Live!

Get 1:1 Help Now