【问题标题】:Postback Request of ASP.NET Controls are taking too much timeASP.NET 控件的回发请求花费了太多时间
【发布时间】:2020-12-27 15:09:41
【问题描述】:

我创建了一个 asp.net 网站http://www.oureasymart.com,它在 localhost 中运行良好。但是在将其托管给godaddy后,当单击类似按钮的asp.net控件时,执行其操作需要花费大约1分钟的时间。这个问题是针对每个页面的每个asp.net控件。 我认为后面的代码或单击事件没有问题,因为我尝试了一个简单的 Response.Redirect() 方法来在单击该按钮时移至下一页,但仍然需要相同的时间。我也尝试在 Jquery Ajax 的帮助下调用相同的方法,它工作正常。我还启用了跟踪,在该跟踪中我检查了没有事件甚至需要 1 秒。请查看跟踪信息的代码和屏幕截图,并提出可能的问题。 追踪信息:https://drive.google.com/file/d/19Cl6wpe_Y20FCzxI9d0bUvj8BdaUdgjR/view?usp=drivesdk

通过搜索产品,然后单击产品搜索页面中的页面索引来获取跟踪信息屏幕截图。

<div class="row">
                    <asp:Repeater ID="repeater1" runat="server">
                        <ItemTemplate>
                            <div id="lblsp" class="col-lg-3 col-md-3 col-sm-6 col-xs-12">
                                <div class="my-list hovereffect w3l-pricehkj">
                                    <img src='data:images/png;base64,<%# Eval("Img1") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Img1")): string.Empty %>' alt="IMG-PRODUCT" style="max-height: 200px;min-height:200px" />
                                    <h3><%#Eval("Prod_Name") %></h3>
                                    <div class="single-infoagile" style="margin-top: 10px">
                                            <ul>
                                                <li>Cash on Delivery Eligible.
                                                </li>
                                                <li>Shipping Speed to Delivery.
                                                </li>

                                            </ul>
                                        </div>
                                    <h6><span>₹<%#Eval("Cost")%></span></h6>

                                    <asp:HiddenField ID="hid_packageId" runat="server" Value='<%#Eval("Prod_Name") %>' />
                                    <div class="overlay">
                                        <h2><%#Eval("Prod_Name") %></h2>
                                        <a class="info" href="ViewProduct.aspx?Name=<%#Server.UrlEncode(Eval("Prod_Name").ToString()) %>">View Details</a>
                                        <input id="btn_addtocart" type="button" class="info" causesvalidation="false" value="Add to Cart" />

                                    </div>
                                </div>

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

            </div>
            <div class="pagechange">
                            <table>
                                <tr>
                                    <asp:Label ID="lblpage" runat="server" Text="" Font-Size="Medium"></asp:Label></tr>
                                <tr>
                                    <td>
                                        <input id="btn_Prev" type="button" class="btn-link" causesvalidation="false" value="<" />
                                    </td>
                                    <td>
                                        <asp:DataList ID="rptPaging" runat="server" OnItemCommand="rptPaging_ItemCommand" OnItemDataBound="rptPaging_ItemDataBound"
                                            RepeatDirection="Horizontal">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="lbPaging" runat="server" CommandArgument='<%# Eval("PageIndex") %>' CommandName="newPage"
                                                    Text='<%# Eval("PageText") %> ' Width="20px">      
                                                </asp:LinkButton>
                                            </ItemTemplate>
                                        </asp:DataList>
                                    </td>
                                    <td>
                                        <input id="btn_Next" type="button" class="btn-link" causesvalidation="false" value=">" />
                                    </td>
                                </tr>
                            </table>
                        </div>

    **Code Behind:**

 protected void rptPaging_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (!e.CommandName.Equals("newPage")) return;
            CurrentPage = Convert.ToInt32(e.CommandArgument.ToString());
            BindDataIntoRepeater();
        }

 private void BindDataIntoRepeater()
        {
            if(_pgsource.DataSource ==null)
            {
                var dt = GetDataFromDb();
                _pgsource.DataSource = dt;
            }
            _pgsource.AllowPaging = true;
            // Number of items to be displayed in the Repeater
            _pgsource.PageSize = _pageSize;
            _pgsource.CurrentPageIndex = CurrentPage;
            // Keep the Total pages in View State
            ViewState["TotalPages"] = _pgsource.PageCount;
            // set Previous, Next buttons visible          
            //lblPrevious.Visible = !_pgsource.IsFirstPage;
            //lbNext.Visible = !_pgsource.IsLastPage;
            // Bind data into repeater
            
            ProductSearch p = new ProductSearch();
            p.repeater1.DataSource = _pgsource;
            p.repeater1.DataBind();
            // Example: "Page 1 of 10"
            int total = 0;
            if (ViewState["total"] != null)
            {
                total = (int)ViewState["total"];
            }
            lblpage.Text = "Page " + (CurrentPage + 1) + " of " + _pgsource.PageCount + "(" + total + " resultS)";
            // Call the function to do paging
            HandlePaging();
        }
        private void HandlePaging()
        {
            var dt = new DataTable();
            dt.Columns.Add("PageIndex"); //Start from 0
            dt.Columns.Add("PageText"); //Start from 1

            _firstIndex = CurrentPage - 5;
            if (CurrentPage > 5)
                _lastIndex = CurrentPage + 5;
            else
                _lastIndex = 10;

            // Check last page is greater than total page then reduced it 
            // to total no. of page is last index
            if (_lastIndex > Convert.ToInt32(ViewState["TotalPages"]))
            {
                _lastIndex = Convert.ToInt32(ViewState["TotalPages"]);
                _firstIndex = _lastIndex - 10;
            }

            if (_firstIndex < 0)
                _firstIndex = 0;

            // Now creating page number based on above first and last page index
            for (var i = _firstIndex; i < _lastIndex; i++)
            {
                var dr = dt.NewRow();
                dr[0] = i;
                dr[1] = i + 1;
                dt.Rows.Add(dr);
            }

            rptPaging.DataSource = dt;
            rptPaging.DataBind();
        }

【问题讨论】:

    标签: c# asp.net entity-framework


    【解决方案1】:

    我找到了原因。实际上在按钮单击时查看状态有大量数据,因为 我使用的中继器控制。这导致延迟到达服务器的到达请求。我禁用了转发器的视图状态,这解决了问题。

    【讨论】:

      猜你喜欢
      • 2014-03-22
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多