locked
after adding new user control loading in browser is slow RRS feed

  • Question

  • User-1690769677 posted

    Hello

    After adding new user control "DocTransList" to my page loading page is very slow (around 45 second) .

    Before when it had just 1 user control "DocumentList" loading page was around 10 seconds.

    Now I do not know what the problem is and how I can solve this problem.

    My page:
    Transmittals.aspx
    <%@ Page Language="C#" MasterPageFile="~/MasterAdmin.master" AutoEventWireup="true" CodeFile="Transmittals.aspx.cs" Inherits="Transmittals" Title="Untitled Page" %>
    
    <%@ Register src="Controls/DocumentList.ascx" tagname="DocumentList" tagprefix="uc1" %>
    
    <%@ Register src="Controls/DocTransList.ascx" tagname="DocTransList" tagprefix="uc2" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    
    <h1>Transmittals</h1>
    
     <asp:UpdateProgress ID="UpdateProgressAddTransmittal" runat="server" AssociatedUpdatePanelID="updAddTransmittal">
        <ProgressTemplate>
          <asp:Image ID="imgProgress" runat="server"  />
        </ProgressTemplate>
      </asp:UpdateProgress>
      
      <asp:UpdatePanel ID="updAddTransmittal" runat="server" RenderMode="Block">
        <ContentTemplate>
    
          <p><asp:Button ID="btnShowAddTransmittal" runat="server" Text="Add an Transmittal..." 
    	       />
              
            </p>
    	    
          <div id="divAddTransmittal" runat="server" visible="false">
            <div>
              <div>
                Transmittal No: <asp:TextBox ID="txtTransmittalNo" runat="server" />
                <asp:RequiredFieldValidator ID="vldTransmittalNo" runat="server" ErrorMessage="TransmittalNo required" ControlToValidate="txtTransmittalNo" />
              </div>
              <div>
                Transmittal Date: <asp:TextBox ID="txtRevDATE" runat="server" />
                <asp:RequiredFieldValidator ID="vldRevDATE" runat="server" ErrorMessage="RevDATE required" ControlToValidate="txtRevDATE" />
              </div>
              <asp:Button ID="btnAddTransmittalNo" runat="server" Text="Add this Transmittal" 
    		         />
    		    </div>
          </div>
          
        </ContentTemplate>
      </asp:UpdatePanel>
        
    
    <asp:UpdatePanel ID="updTransmittals" runat="server" RenderMode="Block">
        <ContentTemplate>
          <asp:GridView ID="GridViewTransmittals" runat="server" AutoGenerateColumns="False" 
    	  onrowdatabound="GridViewTransmittals_RowDataBound">
    	  <columns>
    		  <asp:hyperlinkfield DataNavigateUrlFields="TransID" 
    		    DataNavigateUrlFormatString="~/Transmittal.aspx?TransID={0}" DataTextField="TransmittalNo" 
    		    HeaderText="TransmittalNo">
    		  </asp:hyperlinkfield>
    		   
    	    <asp:TemplateField HeaderText="Documents">
    	      <ItemTemplate>
    		     <uc1:DocumentList ID="DocumentList1" runat="server" />
    	      </ItemTemplate>
    	    </asp:TemplateField>
    	    
    	    <asp:TemplateField HeaderText="rev">
    	      <ItemTemplate>
    		    <uc2:DocTransList ID="DocTransList2" runat="server" />
    	      </ItemTemplate>
    	    </asp:TemplateField>
    	     
    	  </columns>
      </asp:GridView>
            
        </ContentTemplate>
      </asp:UpdatePanel>
      
     
    
    </asp:Content>
    

    ---------------------------------------------------------------

    Code behind page:
    
    Transmittals.aspx.cs
    
    public partial class Transmittals : System.Web.UI.Page
    
    {
    
       
    
        class TransmittalPresentationModel
    
        {
    
            public int TransID { get; set; }
    
          public String TransmittalNo { get; set; }
    
          public IEnumerable<tblDocument> Documents { get; set; }
    
          public IEnumerable<tblTransmittall> DocTrans { get; set; }
    
        }
    
     
    
        private EDMSDataContext _DataContext;
    
     
    
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
          _DataContext = new EDMSDataContext();
    
           
    
     
    
          if (!IsPostBack)
    
          {
    
            DisplayAuthors();
    
          }
    
        }
    
     
    
        private void DisplayAuthors()
    
        {
    
          var query =
    
            from transmittal in _DataContext.tbltransmittalNos
    
           
    
            orderby transmittal.TRANSMITTAL
    
            select new TransmittalPresentationModel
    
                   {
    
                       TransID = transmittal.TransID,
    
                     TransmittalNo = transmittal.TRANSMITTAL,
    
                   
    
                    Documents=transmittal.tblTransmittalls.Select(Transmittals=>Transmittals.tblDocument),
    
                    DocTrans=transmittal.tblTransmittalls
    
     
    
                    
    
                   };
    
          GridViewTransmittals.DataSource = query.ToList();
    
          GridViewTransmittals.DataBind();
    
        }
    
     
    
        protected void GridViewTransmittals_RowDataBound(object sender, GridViewRowEventArgs e)
    
        {
    
          if (e.Row.DataItem == null)
    
            return;
    
     
    
          TransmittalPresentationModel transmittal = (TransmittalPresentationModel)e.Row.DataItem;
    
           
    
          
    
          DocumentList documentList = (DocumentList)e.Row.FindControl("DocumentList1");
    
          DocTransList doctranslist = (DocTransList)e.Row.FindControl("DocTransList2");
    
           
    
          documentList.Documents = transmittal.Documents;
    
          documentList.DataBind();
    
     
    
          doctranslist.DocTrans = transmittal.DocTrans;
    
          doctranslist.DataBind();
    
        }

       ------------------------------------------------------------------

    User control: DocumentList.ascx
    
    
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="DocumentList.ascx.cs" Inherits="DocumentList" %>
    <asp:GridView ID="GridViewDocuments" runat="server" AutoGenerateColumns="False" 
      BorderStyle="None" ShowHeader="False" Width="100%">
      <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="DocId" 
          DataNavigateUrlFormatString="~/Document.aspx?DocId={0}"
          DataTextField="DocumentNo" 
          HeaderText="Document No" />
         
      </Columns>
    </asp:GridView>
    

    ---------------------------------------------------------------

    DocumentList.ascx.cs
    public partial class DocumentList : System.Web.UI.UserControl
        {
            private IEnumerable<tblDocument> _Documents;
    
            public IEnumerable<tblDocument> Documents
            {
                set { _Documents = value; }
            }
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            public override void DataBind()
            {
                base.DataBind();
                GridViewDocuments.DataSource = _Documents;
                GridViewDocuments.DataBind();
                
            }
        }
    




    }

     -----------------------------------------------------

    DocTransList.ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeFile="DocTransList.ascx.cs" Inherits="DocTransList" %>
    <asp:GridView ID="GridViewDocTrans" runat="server" AutoGenerateColumns="False" 
      BorderStyle="None" ShowHeader="False" Width="100%">
      <Columns>
        <asp:HyperLinkField DataNavigateUrlFields="DocId" 
          DataNavigateUrlFormatString="~/Document.aspx?DocId={0}"
          DataTextField="rev" 
          HeaderText="rev" />
          
      </Columns>
    </asp:GridView>

    ---------------------------------------------------------------------

    DocTransList.ascx.cs
    
    public partial class DocTransList : System.Web.UI.UserControl
    
    {
    
        private IEnumerable<tblTransmittall> _DocTrans;
    
     
    
        public IEnumerable<tblTransmittall> DocTrans
    
        {
    
            set { _DocTrans = value; }
    
        }
    
     
    
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
     
    
        }
    
     
    
        public override void DataBind()
    
        {
    
            base.DataBind();
    
     
    
            GridViewDocTrans.DataSource = _DocTrans;
    
            GridViewDocTrans.DataBind();
    
     
    
        }
    
    }
    
     
    
    
    




    Wednesday, September 12, 2012 3:17 AM

Answers

  • User3866881 posted

    Hi again:)

    Please try this instead of LINQ:

    public partial class DocTransList : System.Web.UI.UserControl
    
    {
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
               if(!IsPostBack)
               {
                
                       using(SqlDataAdapter adapter = new SqlDataAdapter("select * from xxx",new SqlConnection("conn str"))
                       {
                          DataTable dt = new DataTable();
                          adapter.Fill(dt);
                          GridView.DataSource = dt;
                          GridView.DataBind();
                       }
    
               }
    
        }
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 14, 2012 5:44 AM

All replies

  • User3866881 posted

    public override void DataBind()

    Hello,

    If you override the function of DataBind for the Page class,this will be rendered again and again;So I suggest you do binding only once——

    public partial class DocTransList : System.Web.UI.UserControl
    
    {
    
        private IEnumerable<tblTransmittall> _DocTrans;
    
     
    
        public IEnumerable<tblTransmittall> DocTrans
    
        {
    
            set { _DocTrans = value; }
    
        }
    
     
    
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
               if(!IsPostBack)
               {
                 GridViewDocTrans.DataSource = _DocTrans;
    
                 GridViewDocTrans.DataBind();
    
               }
    
        }
    
    }
    Thursday, September 13, 2012 8:48 PM
  • User-1690769677 posted

    thanks a lot

    i did it but still is slow. one guy in the forum told, it seems this is problem of LINQ code because it needs connection for each row. but i do not know how to solve it.

    Best Regards

    Friday, September 14, 2012 5:04 AM
  • User3866881 posted

    Hi again:)

    Please try this instead of LINQ:

    public partial class DocTransList : System.Web.UI.UserControl
    
    {
        protected void Page_Load(object sender, EventArgs e)
    
        {
    
               if(!IsPostBack)
               {
                
                       using(SqlDataAdapter adapter = new SqlDataAdapter("select * from xxx",new SqlConnection("conn str"))
                       {
                          DataTable dt = new DataTable();
                          adapter.Fill(dt);
                          GridView.DataSource = dt;
                          GridView.DataBind();
                       }
    
               }
    
        }
    
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, September 14, 2012 5:44 AM