While ASP.NET gives a great validator set of controls, now and then you have to "move your own" so to talk when making your controls. What's more, on the off chance that you have some AJAX preparing with your buttons in the background (for instance, sparing a record in a popup window) you run the danger of having "twofold spares" happening when the client clicks on the button and nothing happens instantly.

Having battled with this issue myself recently, it took somewhat more work than expected to get this to work legitimately. Here's the manner by which you get everything to play pleasantly together.

The first step is to wire up your code behind occasion that does your handling. In case you're doing this in C# you setup your Onclick occasion:

<asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" />

In case you're doing this in Vb.net, there's no compelling reason to utilize the Onclick value as a part of your button, you can go straight to the code behind, make your strategy name, and utilize the Handles pivotal word, pointing out your buttons click occasion:

Protected Void Sub btnSave_Click Handles btnSave.Click
' Code here
End Sub

The next step is to do our validation using Javascript (we’re using jQuery in here).

function validatePage()
{
    var check = true;

    // Check only simple textbox for now
    if ($("#txtImportant").val() == '') check = false;

    if (!check)
    {
       alert('Missing data. Please complete');
       return false;
    }
    else
    {
       $("#MainContent_btnSave").val('Processing...');
       $("#MainContent_btnSave").attr("disabled", true);
       return true;
    }
}

There are several vital notes to this capacity. The main is not to overlook that Asp.net as a matter of course likes to help particularly name your server controls, subsequently the "Maincontent_" prefix on our spare button. You can utilize the Clientidmode property in the event that you have to get around this. The following is that we keep the client from twofold clicking the spare catch by handicapping the catch and transforming its content to say "Handling… " Finally, we just debilitate the button if the acceptance succeeds. This keeps us from needing to handicap and re-empower the button focused around the results. Strangely it likewise verifies that our return value in the HTML component forms accurately, which was likely one of the greatest glitches I ran crosswise over amid this process.

Presently we have to wire up the Javascript handling. To do this, we utilize the Onclientclick technique that is accessible for most .Net server controls. While taking a gander at our code above looks clear enough (return false to prematurely end the script or valid to proceed with the post back) we do need to change our rationale somewhat. Having a "return genuine" explanation doesn't let the button proceed with its post back, it will make it quit handling (very nearly the same as a return false summon). Rather, we let our rationale just prematurely end if our acceptance fizzled:

<asp:Button ID="btnSave" runat="server"
            Text="Save"
            OnClick="btnSave_Click"
            OnClientClick="if (!validatePage()) {return false;}" />

At long last, following we're overriding the HTML onclick occasion on the control (on account of the Oncilentclick property) that regardless of the possibility that your acceptance strategy succeeds, the code behind system won't shoot. To work around this, we utilize the Usesubmitbehavior property of the button control and set it to false. What this does is attaches the suitable __dopostback call after our Javascript code. The last code for your button resembles this:

<asp:Button ID="btnSave" runat="server"
            Text="Save"
            OnClick="btnSave_Click"
            OnClientClick="if (!validatePage()) {return false;}"
            UseSubmitBehavior="false" />

That is all there is to it. Presently when you click on the button, if the acceptance falls flat, you'll get the caution box. Something else, the button will get to be crippled with a "handling" message and your code behind strategy will run.