I need to show loading image in asp.net page on submit event. I searched for a lot of ideas here and there but did not found a perfect solution for me. Still, I was able to write one myself. Though, one such is here show loading image while the page is loading but I dont think it'll look for page validation.
JS that I call at page submit.
$(document).ready(function () {
$(this).submit(function () {
$("#overlay").fadeIn(30);// Call (Show) loading box by default.
if (Page_ClientValidate() != null) //Check if there is a validation on page.
{
if (!Page_ClientValidate()) {//If Validation returns false then hide the loading box
$("#overlay").hide();
}
}
});
});
Here is my loading div:
<div style="display: none" id="overlay">
<div id="modalprogress">
<div id="theprogress">
<img alt="Loading... Please wait" src="../App_Themes/Theme1/images/processing.gif">
</div>
</div>
</div>
This div remains hidden by default. As soon as a submit button is clicked, it calls for Page_ClientValidate() method that is used for validation of page. Works fine for me but has few issues.
A button with a different or no ValidationGroup
will fire this Page_ClientValidate()
of other ValidationGroup
present on page, and then shows the error message in validation summary, though it submits the page, but:
- It shows the validation summary that is irrelevant/ for a moment (until the requested page is returned).
- In case a button with a
ValidationGroup
is pressed, and a validation error occurs, it would then suppress all the submits/javascript methods that follow. - Any way to call the same in DropDown or CheckBox methods
AutoPostBack
Events?
Note#: I am trying to avoid the update panel thing, and other ajax call ideas as of now. Just need some optimization in the above code.