BLoB
BLoB

Reputation: 9725

Slow button response

I'm using font awesome on asp .net buttons as follows (this method is used so that the font awesome icon is dran in the button, if using the usual asp:button control, it will not allow html tags to be executed within itself, and so the font awesome fonts will not work):

This method (when compared to the typical method) seems to introduce a small almost half a second delay in the visible response in the browser.

<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>

To handle the server side response is the method:

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));
}

If I register the click event handler using the typical method then the visible result in the browser is almost instantaneous, e.g.

<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));
}

So the question is, why the slow down and can it be sped up (while maintaining the ability to use font awesome within the button)?

P.S. I've attempted several methods to speed up the button response such as disabling the viewstate but nothing I have done seems to have any affect

Upvotes: 0

Views: 1090

Answers (1)

Giox
Giox

Reputation: 5123

I suggest you to use the LinkButton control. I use them successfully with any delay and possibility to style them as I want with fa icons too.

Here is my code:

<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>

I have also applied the style of the button from bootstrap

Upvotes: 1

Related Questions