2

I have a button that is executing some insertion into the database.

Problem is when user fills the form and click on the buttons more than one time insertion process executed multiple times.

So i disabled the button on "OnClientClick" of button using script but it does not execute the server side Click event.

here is my button :

<asp:Button ID="btnContinue" runat="server" Text="Continue To Application >>" OnClick="btnContinue_Click" ValidationGroup="criteria" OnClientClick="DiableButton(this)"></asp:Button>

function that disables the button

function DiableButton(btn) {   

    $(btn).attr("disabled", "disabled");        
    $("[Id$='hfDisableBtn']").val($(btn).attr("id"));      

}

function that enables the function that is called from the server side after executing insertion

function EnableButton() {
   var btn = $("[Id$='hfDisableBtn']").val();
   $(btn).removeAttr("disabled");
   $("[Id$='hfDisableBtn']").val("");    
}

what i want is

1) first disable button on click if all the validation satisfied (like Require filed validator)
2) then call the server side click event of that same button
3) enable that button after executing server side click event

How can i achieve this ???

Please help me Thanks is advance

2
  • show the validation...after validation you can trigger the button attribute change. Commented May 29, 2015 at 13:02
  • I have used asp.net validation like "RequiredFieldValidator" and "RegularExpressionValidator", you can see that in my button as i have used ValidationGroup="criteria" Commented May 29, 2015 at 13:05

3 Answers 3

1

This can be achieved by replacing your asp:Button with the html button and on that button click create an AJAX call to your server function (needs to be marked as WebMethod) then you can exactly follow your requirements

1) first disable button on click if all the validation satisfied (like Require filed validator)
2) then call the server side click event of that same button
3) enable that button after executing server side click event
Sign up to request clarification or add additional context in comments.

Comments

0

I am not sure if your JS code works as you expect, but if the functions work then it should too

1) first disable button on click if all the validation satisfied (like Require filed validator)
2) then call the server side click event of that same button

You said that the function works but doesn't fire the server function so here you only have to add the return true; in your JS function and the server function will be called

3) enable that button after executing server side click event

In your server side function add this line to call the JS function

ScriptManager.RegisterStartupScript(this, this.GetType(), "Funct", "EnableButton();", true);

Also, if you are storing the ID of the button to exclusively use it in these two functions, you can leave them like this:

function DiableButton(btn) {   
    $(btn).attr("disabled", "disabled");             
    return true;
}

function EnableButton() {
   var btn = $('#<%=btnContinue.ClientID %>').val();
   $(btn).removeAttr("disabled");  
}

Hope it helps

1 Comment

The required field validator does its work before call the server, and even before trigger the onclientclick function, so you don't have to be worried about
0

Try this.

 $('#btnContinue').prop('disabled', false); 
 $('#btnContinue').click();
 $('#btnContinue').prop('disabled', true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.