0

I have an ASP.NET WebForms webpage that we need to show an image on page once a page is valid. At the moment, the image will show whether there is a validation error or not. How do we only display the image if there's no validation errors on the page?

Once the image has appeared, the code will be doing some background processing so it can't return control to the webpage at that point.

Any Javascript/JQuery script is welcome or advice please.

MiscellaneousUser
  • 2,915
  • 4
  • 25
  • 44
  • Where are you doing your validations ? If it is on server-side you can set the image run-at server=true, and set Visible to false. You can also set the style property from C# to display none in case of validation failures. – Dot_NET Pro Jun 09 '17 at 09:48
  • We're using validation controls. Therefore if the form is valid, we want a Loader image to display whilst the button onclick event is being actioned. – MiscellaneousUser Jun 09 '17 at 15:40

1 Answers1

0

What you can do is that on client side, form submit button add a function to check if all the validations have passed and then you can show the Loader image. Please see below code:

<input type="submit" value="Submit" onclick"ValidatePage();" />

<script type="text/javascript">

function ValidatePage() {

    if (typeof (Page_ClientValidate) == 'function') {
        Page_ClientValidate();
    }

    if (Page_IsValid) {
        //Display Loader Image
       document.getElementById("yourbutton").click();
    }
    else {
        //alert('Page is not valid!');
    }
}

Determine if page is valid in JavaScript - ASP.NET

How to check Page.Validate() on client side (JavaScript) in ASP.Net?

Dot_NET Pro
  • 2,095
  • 2
  • 21
  • 38