ASP.NET – View a loading on the postback

One of the peculiarities of the ASP.NET framework is definitely postback, often used in many controls within the same page.
Each time an item, such as a select or a checkbox, changes status, and the Autopostback property is set to true, the web page is reloaded.

There are instances where page loading is not immediate, so, to make this mechanism less unpleasant to users, it is possible to make a load on each postback, just create a hidden div with your favorite animated gif o bootstrap spinner and stick to the form the onsubmit event that will display the div.

$('form').attr("onsubmit", "$('.loading').show()")

There is no need to hide the div, recharging completely the page, the div is set to its initial state that is hidden.

Leave a Comment

Your email address will not be published. Required fields are marked *