ItemDataBound减慢了我的页面渲染速度 [英] ItemDataBound slowing my page rendering

查看:75
本文介绍了ItemDataBound减慢了我的页面渲染速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1 我在这里遇到的第一个问题,如果我不熟练使用技术,请原谅语言,因为该网站使我成为了来自深非洲莫桑比克的自学开发人员.

1My first question ever here, forgive if I am not fluent in tech language because I am a self taught developer from deep Africa Mozambique, thanks to this site.

我的问题是我有一个

public void topicView_ItemDataBound(object sender,e)

在我的代码中,该代码用于具有中继器的特定aspx页面,该页面从数据表接收其信息(如果我的术语正确的话.)ItemDataBound事件用于将我的控件安排在中继器中,以便隐藏,禁用和禁用根据确定的标准显示其他控件.现在,我注意到ItemDataBound事件使我的页面加载时间减慢了20到40秒,这是非常糟糕的,即使在回发时也是如此.当我删除I​​temDataBound事件.我运行顺利.但是我无法处理ItemDataBound事件,因为它是我知道如何以交替条件安排转发器的唯一方法.这是快速解答的常见问题,还是我应该发布完整的代码?此事件仅在2页上发生.如果有任何帮助,我正在使用c#.net.4.5

In my code behind for a particular aspx page with a repeater, that receives its info from a datatable (if my terminology is correct.) The ItemDataBound event is to arrange my controls in a repeater for the purpose of hiding, disabling and showing other controls according to the determined criterias. Now I have noticed that the ItemDataBound event is slowing my page load time by some 20 to 40 seconds which is really bad, even on post back. When i remove the ItemDataBound events. I am running smoothly. But i can't work with out the ItemDataBound event since its the only way i know how to arrange a repeater with alternating conditions. Is this a common problem with a quick answer or should i post my full code?? this only happens on 2 pages with this event. I am using c# if thats of any help. net.4.5

public void topicView_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            // Show or hid div here
            HiddenField MediaType = (HiddenField)e.Item.FindControl("MediaType");
            HiddenField PageAdmin = (HiddenField)e.Item.FindControl("PageAdmin");
            HiddenField f1 = (HiddenField)e.Item.FindControl("F1");
            HiddenField PP = (HiddenField)e.Item.FindControl("PP");
            HiddenField isread= (HiddenField)e.Item.FindControl("isread");
            HiddenField tread = (HiddenField)e.Item.FindControl("tread");

            // Label Label2 = (Label)e.Item.FindControl("Label2");
            // Label2.Text = myDDL.Value;
            System.Web.UI.HtmlControls.HtmlContainerControl image_video = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("image_video");

            System.Web.UI.HtmlControls.HtmlContainerControl image_pic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("image_pic");
            System.Web.UI.HtmlControls.HtmlContainerControl PP1 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("PP1");
            System.Web.UI.HtmlControls.HtmlContainerControl userpic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("userpic");
            System.Web.UI.HtmlControls.HtmlContainerControl compic = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("compic");
            System.Web.UI.HtmlControls.HtmlContainerControl userpic2 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("userpic2");
            System.Web.UI.HtmlControls.HtmlContainerControl compic2 = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("compic2");
            System.Web.UI.HtmlControls.HtmlContainerControl pf = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("pf");
            System.Web.UI.HtmlControls.HtmlContainerControl attach = (System.Web.UI.HtmlControls.HtmlContainerControl)e.Item.FindControl("attach");

            LinkButton LinkButton3 = (LinkButton)e.Item.FindControl("LinkButton3");
            LinkButton LinkButton1 = (LinkButton)e.Item.FindControl("LinkButton1");
            Label Label4 = (Label)e.Item.FindControl("Label4");
            Label Label10 = (Label)e.Item.FindControl("Label10");

            System.Web.UI.WebControls.Image readsign = (System.Web.UI.WebControls.Image)e.Item.FindControl("readsign");
            System.Web.UI.WebControls.Image Image2 = (System.Web.UI.WebControls.Image)e.Item.FindControl("Image2");

            if (MediaType.Value == "video")
            {
                image_video.Visible = false;
                image_pic.Visible = true;
                Image2.ImageUrl = "~/images/readmail.png";

            }


            if (MediaType.Value == "image")
            {
                image_video.Visible = true;
                image_pic.Visible = false;

            }

            if (MediaType.Value == "" ) { attach.Visible = false; } else { attach.Visible = true; }

            if (PageAdmin.Value == "False")
            {
                compic.Visible = false;
                userpic.Visible = true;
                userpic2.Visible = true;
                compic2.Visible = false;
            }
            if (PageAdmin.Value == "True")
            {
                userpic.Visible = false;
                compic.Visible = true;
                userpic2.Visible = false;
                compic2.Visible = true;
            }

            if (isread.Value == "True")
            {
                readsign.ImageUrl = "~/images/readmail.png";
                Label4.Text = "foi lido ";
                Label10.Text = tread.Value;
             }
     }

}

和我的中继器的aspx代码:

and my aspx code for the repeater:

 <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1" 
 OnItemDataBound="topicView_ItemDataBound"><ItemTemplate> 
 <div id="messages" style="margin-bottom: 10px">
    <asp:HiddenField ID="Status" runat="server" 
 Value='<%#""+Eval("Isreplyed") %>' />
    <asp:HiddenField ID="Pageadmin" runat="server" 
 Value='<%#""+Eval("PageAdmin") %>'/>
    <asp:HiddenField ID="MediaType" runat="server" 
Value='<%#""+Eval("MediaType") %>' />
    <asp:HiddenField ID="isread" runat="server" Value='<%#""+Eval("Isread") 
 %>' />
    <asp:HiddenField ID="tread" runat="server" Value='<%#""+Eval("tread","
 {0:d / MM " + "@" + " HH:mm}") %>' />
    <div id="Omsg" style="padding: 5px; border: thin solid #FFFFFF; box-
 shadow:rgba(255, 255, 255,0.9) 0 0 7px; background-color: #FFFFFF;border-
 radius:5px; " >
 <table style="width: 100%; text-align: left; margin-left: 0px;">
  <tr><td colspan="2">
      <asp:Image ID="readsign" runat="server" Height="25" Width="25" 
ImageUrl="~/images/newmail.png" />
      <asp:Label ID="Label4" runat="server" Text='<%# ""+Eval("Isreplyed") 
%>' Font-Size="X-Small" ForeColor="#999999"></asp:Label>&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label10" runat="server" Text='<%#""+Eval("datesent","{0:d / 
MM " + "@" + " HH:mm}") %>' Font-Size="X-Small" ForeColor="#999999">
</asp:Label>
      </td></tr>         
   <tr>

                <td style="width: 66px; text-align: left;"><a id="pps" ><div 
id="compic" ClientIDMode="Static" runat="server"><img id="PP1" alt="" 
class="img-rounded" src='<%#"/ProfilePictures/"+Eval("logo") %>' 
style="width: 50px; height: 50px" /></div><input id="Hidden2" type="hidden" 
runat="server" value='<%#"/ProfilePictures/"+Eval("logo") %>' /></a>
                    <div id="userpic" clientidmode="Static" runat="server">

                        <img alt="" class="img-circle" 
src='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' style="width: 50px; 
height: 50px" />
                    </div><input id="Hidden3" type="hidden" runat="server" 
value='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' />

                     </td>
                <td style="line-height: 15px"> <div id="compic2" 
ClientIDMode="Static" runat="server"> <a  href='<%#"/Landing.aspx?
Restid="+Eval("id") %>' ><asp:Label ID="Label2" class="head" runat="server" 
Text='<%# ""+Eval("name") %>' Font-Size="Medium" ForeColor="#B9A47B">
</asp:Label> </a><a/><br/>
                      <asp:Label ID="CName" runat="server" 
Text='<%#""+Eval("slogan") %>' Font-Size="Smaller"></asp:Label>.   ...</div>
                     <div id="userpic2" ClientIDMode="Static" 
runat="server"><a  href='<%#"/Landing.aspx?Restid="+Eval("Username") %>' >
<asp:Label ID="Label8" class="head" runat="server" 
Text='<%#""+Eval("Username") %>' Font-Size="Large" ForeColor="#B9A47B">
</asp:Label> <a/><br/>
                      <asp:Label ID="Label9" runat="server" 
Text='<%#""+Eval("Job") %>' Font-Size="Smaller"></asp:Label></a>
                         <br />
                         <a/>
<a href='<%#"notificationmaster.aspx?BlogId="+Eval("Blogid") %>'> <asp:Label 
ID="Label5" runat="server" Text='<%# "Respondendo à publicação :  
"+Eval("BlogTitle") %>' Font-Size="smaller" ForeColor="#B9A47B"></asp:Label>
</a><br/>


                    </div>
                   <a/><span style="font-size: x-small; color: #999999"> 
enviado : </span><asp:Label ID="Label3" runat="server" 
Text='<%#""+Eval("datesent","{0:d MMMM yyyy - HH:mm}") %>' Font-Size="X-
Small" ForeColor="#999999"></asp:Label></a>
                    <br />
                   <div id="attach" ClientIDMode="Static" runat="server" > 
<asp:Label ID="Label17" runat="server" Text="Esta mensagem tem anexo" 
ForeColor="#999999" Font-Size="X-Small" Font-Underline="True">
</asp:Label>&nbsp; <img alt="" src="images/attach.png" style="width: 20px; 
height: 20px" /></div>
                </td>



            </tr>
  <tr>
 <td colspan="2">
&nbsp;
<br/>
<div id="msgbody" style="display: none">
<asp:Label ID="Label1" runat="server" Text='<%#""+Eval("mbody") %>'>
</asp:Label><br/>
 <div id="image_pic" ClientIDMode="Static" runat="server" >
            <asp:HiddenField ID="HiddenField1" runat="server" 
Value='<%#"/PostImages/"+Eval("image") %>' />
        <asp:Image ID="Image1" class="img-thumbnail" ClientIDMode="Static" 
runat="server" ImageUrl='<%#"/PostImages/"+Eval("image") %>' alt="Broken" 
Width="100%" />
           </div>
        <div id="image_video" runat="server" onclick="AddView" >
           <video id="PostVedio" runat="server" controls 
poster="/images/chimoioonline.png" src='<%#"/video/"+Eval("video") %>' 
style="width: 100%">
<source src="demo.mp4" type="video/mp4" />
<source src="demo.webm" type="video/webm"/>
<source src="demo.ogv" type="video/ogg"/>
<source src="demo.ogv" type="video/avi"/>             
<p>Fallback code if video isn't supported</p>/
</video></div></div>

 </td>
  </tr>
  <tr>
      <td colspan="2" style="text-align: right">
          <hr style="padding: 2px; margin: 5px" />

          <div id="deletm" style="display: inline-block">
              <input id="Hidden1" type="hidden" runat="server" 
 value='<%#Eval("id")%>' />
          <asp:LinkButton ID="LinkButton3" runat="server" CssClass="btn" 
 onclick="pmdelet" BorderColor="#CCCCCC" BorderWidth="1px"><img 
 src="/images/delete.png" alt="" style=" height: 15px" />
 </asp:LinkButton>&nbsp;&nbsp;<br />
              </div> 
          <div id="sendpm" style="display: inline-block">
              <input id="mido" type="hidden" runat="server" 
 value='<%#Eval("id")%>' />
              <input id="Hidden4" type="hidden" runat="server" 
value='<%#Eval("BlogId")%>' />
              <input id="sender2" type="hidden" runat="server" 
value='<%#Eval("sender")%>' />
              <asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn" 
BorderColor="#CCCCCC" BorderWidth="1px" OnClientClick="" 
PostBackUrl='<%#"PMS.aspx?id=" + Eval("id") + "&BlogId=" + Eval("BlogId")+ 
"&sender=" + Eval("sender")%>' ><img src="images/pvtemail.png" alt="" 
style=" height: 15px" /></asp:LinkButton>&nbsp;&nbsp;
          </div>
          <div id="read" style="display: inline-block">
              <input id="H5" type="hidden" runat="server" 
value='<%#Eval("id")%>' />
              <input id="H7" type="hidden" runat="server" 
value='<%#"/ProfilePictures/"+Eval("logo") %>' />
              <input id="H8" type="hidden" runat="server" 
value='<%#"/ProfilePictures/"+Eval("ProfilePicture") %>' />
              <input id="H6" type="hidden" runat="server" 
value='<%#Eval("Isreplyed")%>' />
              <input id="H14" type="hidden" runat="server" 
value='<%#Eval("Username")%>' />
              <input id="H10" type="hidden" runat="server" 
value='<%#Eval("name")%>' />
              <input id="H13" type="hidden" runat="server" 
value='<%#Eval("Subject")%>' />
              <input id="H9" type="hidden" runat="server" 
value='<%#Eval("BlogTitle")%>' />
              <input id="H11" type="hidden" runat="server" 
value='<%#Eval("datesent","{0:d / MM " + "@" + " HH:mm}")%>' />
              <input id="H12" type="hidden" runat="server" 
value='<%#Eval("mbody")%>' />
              <input id="v5" type="hidden" runat="server" value='<%# 
Eval("video")%>' />
              <input id="p5" type="hidden" runat="server" 
value='<%#Eval("image")%>' />
               <input id="sender" type="hidden" runat="server" 
value='<%#Eval("sender")%>' />
               <input id="Hidden5" type="hidden" runat="server" 
value='<%#Eval("Blogid")%>' />
               <input id="PageAdmin2" type="hidden" runat="server" 
value='<%#Eval("PageAdmin")%>' />
              <asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn"  
BorderColor="#CCCCCC" BorderWidth="1px" OnClientClick="return false"><img 
src="/images/read2.png" alt="" style=" height:15px" /></asp:LinkButton>

          </div>

      </td>
  </tr>
            </table>
     </div>

    <div id="Rmsg">

    </div>


</div>
</ItemTemplate></asp:Repeater>

我的服务器"分析器屏幕截图

推荐答案

这并不是真正的答案,而是让您更深入地研究问题所在的一种方法.(而且很想发表评论)

This is not really an answer, but more a way for you to delve deeper into whats the problem. (And it's to long for a comment)

首先,您需要确保已安装SQL Server管理工具,特别是需要名为SQL Server Profiler的工具.

First of all you need to make sure you have SQL server managment tools installed, in particular you need the tool called SQL server profiler.

在事件探查器中,转到文件"新跟踪"并连接到SQL Server.

In profiler you go to "file" "new trace" and connect to you SQL server.

在跟踪"属性中,仅选择"RPC:completed"和"SQL:BatchCompleted".

In the Trace properties you select only "RPC:completed" and "SQL:BatchCompleted".

现在,您可以运行aspx页面,并且应该在探查器中设置该页面生成的所有SQL查询.您应该注意两件事.

Now you can run your aspx page, and you should se all SQL queries generated by the page in the profiler. There are two things you should look out for.

首先,寻找长时间运行的查询.持续时间列以MS表示,您的任何人都不得超过1000毫秒.

First of all, look for long running queries. The duration column is in MS and you should not have anyone longer than 1000ms.

第二,运行页面时运行的查询数.普通页面不应超过20个查询.通常,当您遇到此问题时,您可以运行数百个.

Secondly, the number of queries run when the page is run. A normal page should not exceed 20 queries. Usualy when you get problems with this, you could run hundreds.

这篇关于ItemDataBound减慢了我的页面渲染速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆