慢按钮响应

问题描述 投票:0回答:1

我在asp .net按钮上使用字体真棒如下(使用此方法,以便在按钮中使用字体真棒图标,如果使用通常的asp:按钮控件,它将不允许在其自身内执行html标记,所以字体真棒字体将无法正常工作):

这种方法(与典型方法相比)似乎在浏览器中引入了几乎半秒的可见响应延迟。

<button id="btn_lastMonth" title="Last Month" onserverclick="Btn_lastMonth_Click" runat="server">
    <i class="fas fa-calendar-alt" aria-hidden="true"></i> Last Month
</button>

处理服务器端响应的方法是:

protected void Btn_lastMonth_Click(object sender, EventArgs e)
{
    this.dp_inspectionDateFrom.SelectedDate = Utility.FirstDayOfMonth(DateTime.Now.AddMonths(-1));
    this.dp_inspectionDateTo.SelectedDate = Utility.GetLastDayOfMonth(DateTime.Now.AddMonths(-1));
}

如果我使用典型方法注册click事件处理程序,那么浏览器中的可见结果几乎是瞬时的,例如,

<asp:Button ID="btn_lastMonth" Text="Last Month" Font-Size="Large" runat="server" />

this.btn_lastMonth.Click += new EventHandler(this.Btn_lastMonth_Click);

private void Btn_lastMonth_Click(object sender, EventArgs e)
{
    this.dp_inspectionDateFrom.SelectedDate = Utility.FirstDayOfMonth(DateTime.Now.AddMonths(-1));
    this.dp_inspectionDateTo.SelectedDate = Utility.GetLastDayOfMonth(DateTime.Now.AddMonths(-1));
}

所以问题是,为什么减速并且可以加速(同时保持在按钮内使用字体真棒的能力)?

附:我尝试了几种方法来加速按钮响应,例如禁用视图状态,但我所做的一切似乎都没有任何影响

c# asp.net performance
1个回答
1
投票

我建议你使用LinkBut​​ton控件。我成功使用它们有任何延迟和可能性,因为我想用fa图标来设计它们。

这是我的代码:

<asp:LinkButton ID="BtnDelete" runat="server" CssClass="btn btn-danger btn-sm btn-delete" OnClick="BtnDelete_Click" data-confirm="Are you sure you want to delete this item?" Text="<i class='fa fa-trash' aria-hidden='true'></i>"></asp:LinkButton>

我也从bootstrap应用了按钮的样式

© www.soinside.com 2019 - 2024. All rights reserved.