Click here to Skip to main content
15,074,483 members
Please Sign up or sign in to vote.
3.67/5 (3 votes)
See more: , +
Hi,

I am having issue with Performance of webpage. I am using LINQ / SQL server 2008 / C# / .Net 4.0
.
List of Controls on the pages:

Master Page:

# Web User Control ( WUC) having DataList
# WUC having TreeView control.
# ContentPlaceHolder

Home Page ( Default page or Content page)
# WUC having DataList and another nested WUC having GridView with few buttons.
.................
Issues:

1. My home page became very heavy. Why?
2. No Cacheing is applied yet. I want to apply cacheing on the page.. Problem is, every content on the page is Dynamic .I think I will have to apply Cache Dependency type of Cacheing. Please advice me Where should I apply cacheing and Which type of Cacheing I should implement.
3. If I put DataSet in cache Please advice will that be sufficient to increase the performance of TreeView controls.
4. If I need to use SiteMap to bind TreeView control, How should I populate SiteMap with DataSet Dynamically? I have table having Information which chnages sometimes.. So I want it to be dynamic...
5. Please advice me the types of Caching I should apply for this page.



I am populating the TreeView as followes:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class admin_WUCCatListNav : System.Web.UI.UserControl
{
    booksDataContext obj = new booksDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {       
      
        GetParentNode();    
       
    }
    public void GetParentNode()
    {   
        TreeView1.Nodes.Clear();        
        TreeView1.ShowLines = true;
        
        DataSet DS= new DataSet();
        DS= obj.DspBookCatBookCatDet();
        TreeNode HeaderNode = new TreeNode("Categories");
        HeaderNode.NavigateUrl = "Default.aspx";
        
        for (Int32 i = 0; i < DS.Tables[0].Rows.Count; i++)
        {    
            TreeNode PNode = new TreeNode();            
            TreeNode CNode = new TreeNode();                      
          
            String catnam1=Convert.ToString(DS.Tables[0].Rows[i]["catnam"]);
            String catcod1 = Convert.ToString(DS.Tables[0].Rows[i]["catcod"]);            
            Int32 j = i;
            PNode.Text = catnam1;
            PNode.Value = catcod1;
            PNode.NavigateUrl = "frmbookbycat.aspx?catcod=" + PNode.Value;            
            CNode.Text = Convert.ToString(DS.Tables[0].Rows[i]["catdetnam"]) + "(" + Convert.ToString(CountBooks(Convert.ToInt32(DS.Tables[0].Rows[i]["catdetcod"]))) + ")";
            CNode.Value = Convert.ToString(DS.Tables[0].Rows[i]["catdetcod"]);
            CNode.NavigateUrl = "frmbookbycat.aspx?catcod=" + Convert.ToString(DS.Tables[0].Rows[i]["catcod"]) + "&catdetcod=" + CNode.Value;
            //CNode.NavigateUrl = "frmbookdets.aspx?catdetcatcod=" + Convert.ToString(DS.Tables[0].Rows[i]["catdetcatcod"]) + "&catnam=" + PNode.Text;
            PNode.ChildNodes.Add(CNode); 
            while(j < DS.Tables[0].Rows.Count-1)
            {               
               String catnam2 = Convert.ToString(DS.Tables[0].Rows[j+1]["catnam"]);
               if (catnam2 == catnam1)
               {
                   TreeNode CNode1 = new TreeNode();
                   CNode1.Text = Convert.ToString(DS.Tables[0].Rows[j + 1]["catdetnam"]) + "(" + Convert.ToString(CountBooks(Convert.ToInt32(DS.Tables[0].Rows[j+1]["catdetcod"])))+ ")";
                   CNode1.Value = Convert.ToString(DS.Tables[0].Rows[j+1]["catdetcod"]);
                   CNode1.NavigateUrl = "frmbookbycat.aspx?catcod=" + Convert.ToString(DS.Tables[0].Rows[j + 1]["catcod"]) + "&catdetcod=" + CNode1.Value; 
                   //CNode1.NavigateUrl = "frmbookdets.aspx?catdetcatcod=" + Convert.ToString(DS.Tables[0].Rows[j + 1]["catdetcatcod"]) + "&catnam=" + PNode.Text; 
                   PNode.ChildNodes.Add(CNode1);
                   i = j + 1;
                   catnam1 = catnam2;
                   j++;
               }
               else
               {
                   break;
               }           
               
            }
            HeaderNode.ChildNodes.Add(PNode);                     
        }        
        TreeView1.Nodes.Add(HeaderNode);
        if (Request.QueryString["catcod"] != null)
        {
            ENode(Request.QueryString["catcod"]);
        }
        TreeView1.DataBind();
    }
    public void ENode(String catcod)    
    {
        
        TreeNode t = new TreeNode();        
        for (Int32 i = 0; i < TreeView1.Nodes.Count; i++)
        {
            TreeNode nd = TreeView1.Nodes[i];
            for (Int32 j = 0; j < nd.ChildNodes.Count;j++)
            {
                if (TreeView1.Nodes[0].ChildNodes[j].Expanded==true)
                {
                    TreeView1.Nodes[0].ChildNodes[j].Collapse();
                }
                t = TreeView1.Nodes[0].ChildNodes[j];
                if (t.Value == catcod)
                {
                    t.Expand();
                }
            }
        }
        
    }
    public Int32 CountBooks(Int32 catdetcod)
    {       
        
        var totalbooks = (from objbooks in obj.tbbooks
                          join objcatdet in obj.tbcatdets on objbooks.bookcatdetcod equals objcatdet.catdetcod
                          where objcatdet.catdetcod == catdetcod                          
                          select objbooks.bookcod).Count();
        return totalbooks;
    }
}


----------
Thanks,
[removedemailaddress]
Posted
Updated 1-Jan-11 0:04am
v3
Comments
   
The efficiency of existing (different) TreeView components is indeed a serious problem.
There is a good concept of virtual tree view, but I could not find any good implementation for .NET.
I understand how to do this, but this is too big work to do it right now. (There was a pretty good implementation for Delphi, but only for native Windows platform, not .NET.) So, I cannot provide any useful answer, but your question deserves my 5.
Jass22 2-Jan-11 3:48am
   
thank you for your reply

OP wrote:
1. My home page became very heavy. Why?

May be you are loading heavy number of nodes in treeview. Also check this one too Treeview node limit[^]
OP wrote:
2. No Cacheing is applied yet. I want to apply cacheing on the page.. Problem is, every content on the page is Dynamic .I think I will have to apply Cache Dependency type of Cacheing. Please advice me Where should I apply cacheing and Which type of Cacheing I should implement.

Caching Dynamic Pages with ASP.NET[^]
OP wrote:
3. If I put DataSet in cache Please advice will that be sufficient to increase the performance of TreeView controls.

Surely. How do I cache a dataset to stop round trips to db?[^]
OP wrote:
4. If I need to use SiteMap to bind TreeView control, How should I populate SiteMap with DataSet Dynamically? I have table having Information which chnages sometimes.. So I want it to be dynamic...

ASP.NET TreeView PopulateNodesFromClient with SiteMapDataSource[^]
Jass22 wrote:

5. Please advice me the types of Caching I should apply for this page.

Caching Techniques in ASP.NET 2.0[^]

Attachments

Also you can use this one too, it will increase the performance
TreeView ASP.NET Populate OnDemand[^]

You may use !IsPostBack[^] in page load event but depends.

OP wrote:
I am having issue with Performance of webpage.

50 Tips to Boost ASP.NET Performance[^]

BTW you have asked your question very well(with explanation, code, list of issues, etc) keep continue always. Cheers. :thumbsup:
   
v2
Comments
Sandeep Mewara 1-Jan-11 13:34pm
   
Deserve a 5!
Jass22 2-Jan-11 3:47am
   
thanx for reply.
Hello,


Thank you very much for your replies...


What I found by debugging my homepage that. The DataList control I use to populate the main data for my page have an Image tage in it. If I disable this "img" tag .. Page loaded and performance is faster.

TreeView Control is performing better now. Cheers Thatraja… for suggesting IsPostBack.. I had just missed it.

How I Debugged?

# Well, I added another content page in the Master Page. (New page controls are: controls of Master page, that’s it…content page is empty).. Pressed F5…. Treeview of Master page loaded efficiently... and causing no problem..... I am very happy with this. :)

# Now, I Dragged a WUC [ Datalist + nested WUC (Gridview)] on this content page..and Pressed F5.. page stared loading slowly.. I found a problem in this WUC.

Next..

# I added a normal Web Form....I placed this WUC onto this webform.. Pressed F5.. Still loading problem in this webform .....Here, I confirmed that there is a problem in this DataList control not TreeView.. :)


Here is code of my DataList Control:

XML
<asp:DataList ID="DataList1" runat="server" CellPadding="0"
    DataKeyField="bookcod" GridLines="Horizontal" HorizontalAlign="Center"
    onitemcommand="DataList1_ItemCommand" RepeatColumns="3" Width="100%">
    <ItemTemplate>
        <table>
            <tr>
                <td>
                    <%--<img src='<%#Eval("bookimg") %>' width="65" height="89" alt="Book Cover" align="left" />--%>
                    &nbsp;Title:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label1" runat="server"
                        Text='<%#Eval("booktit") %>'></asp:Label>
                    <br />
                    &nbsp;Author:&nbsp;&nbsp;&nbsp;&nbsp;<asp:Label ID="Label2" runat="server" Text='<%#Eval("autnam") %>'></asp:Label>
                    <br />
                    &nbsp;Publisher:&nbsp;<asp:Label ID="Label3" runat="server" Text='<%#Eval("pubnam") %>'></asp:Label>
                    <br />
                    &nbsp;Price:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <asp:Label ID="Label4" runat="server" Text='<%#Eval("bookprc") %>'></asp:Label>
                    <br />
                </td>
            </tr>
            <tr>
                <td align="left" valign="top">
                    <asp:ImageButton ID="ImageButton1" runat="server"
                        CommandArgument='<%#Eval("bookcod") %>' Height="20" ImageAlign="Top"
                        ImageUrl="~/images/addtocart3.gif" Width="90" />
                </td>
            </tr>
        </table>
    </ItemTemplate>
</asp:DataList>






=======
If I comment the "img" tag…..Pressed F5.... Page loaded efficiently.. That’s what I want for my Homepage…(Still no caching implementation yet.. :) It means after applying caching techniques It will be more faster.. :) :) )

So..

<b>The issues are:</b>

1. Which type of image (.gif, .jpeg, .png etc) I should use for DataList control for faster loading and bit better quality? This is an online book selling website. It will have pictures of books... and few buttons pictures...only

2. I am storing images on the main directory. And just saving the unique name of image in my database (sql server 2008) for retrieval process (Its normal process I reckon).

In my case, only Admin uploads the images, not the client/user. What is the best approach in dealing with storing images in my case please?


Thanks,
jaspal82ATgmailDOTcom
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900