0

I have three update panel. now i just implement one function that Disable button in update panel when it's clicked and enable it after request end. for few knowledge of javascript i created three function for that here are :

<script>

        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler1);

        function BeginRequestHandler1(sender, args) {
            document.getElementById('<%=btn_Login.ClientID%>').innerText = "Processing..";
            $('#btn_Login').attr('class', 'btn-inactive');
            args.get_postBackElement().disabled = true;
        }

        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler2);

        function BeginRequestHandler2(sender, args) {
            document.getElementById('<%=btn_Subscribe.ClientID%>').innerText = "Processing..";
            $('#btn_Subscribe').attr('class', 'btn-inactive');
            args.get_postBackElement().disabled = true;
        }

        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler3);

        function BeginRequestHandler3(sender, args) {
            document.getElementById('<%=btnsubmit.ClientID%>').innerText = "Processing..";
            $('#btn_Subscribe').attr('class', 'btn-inactive');
            args.get_postBackElement().disabled = true;
        }

    </script>

Here three are diff script for handling three diff btoon request made. here i want to make common script that identify which button made post back request with id then only it's behaviour get changed.

please help me...

Lu Roman
  • 2,220
  • 3
  • 25
  • 40
Shalin Gajjar
  • 229
  • 1
  • 5
  • 15
  • I can't help you with whatever that `Sys.WebForms.PageRequestManager` thing is, but I would recommend giving those functions different names. The above works and calls `add_beginRequest` each time with the function you mean it to have, but the *reason* it works is a bit obscure, and it would fail if you combined those script tags into one script tag (all three calls would use the *last* `BeginRequestHandler` function). That's a bit delicate. – T.J. Crowder Apr 19 '14 at 08:45
  • 1
    Put a `hidden` input in your form and set the value before submitting. – Jeremy J Starcher Apr 19 '14 at 08:46
  • Not related to the problem but you are using basically the exact same behavior in all functions, combine them into one, and pass the id of the element e.g: '#btn_Login' as an argument. – Lu Roman Apr 19 '14 at 08:53
  • @Zarich - can u please explain with code. – Shalin Gajjar Apr 19 '14 at 10:15
  • See this thread: http://stackoverflow.com/questions/23464375/how-to-get-which-button-is-clicked – Jeff Oct 29 '15 at 07:28

2 Answers2

2

You don't need to register add_beginRequest functionality to implement what you need.

Define your buttons something like this:

<asp:Button runat="server" ID="btn_Login" Text="Login" OnClientClick="disableButton(this)" OnClick="ProcessClick_Handler" />

<asp:Button runat="server" ID="btn_Subscribe" Text="Login" OnClientClick="disableButton(this)" OnClick="ProcessClick_Handler" />

<asp:Button runat="server" ID="btnsubmit" Text="Login" OnClientClick="disableButton(this)" OnClick="ProcessClick_Handler" />

And use this script to disable:

<script>
 function disableButton(button){
     $(button).val("Processing..").attr('class','btn-inactive').attr('disabled',true);
 }
</script>

That's it!

Gaurav Pandey
  • 2,798
  • 4
  • 28
  • 41
0

Give every button a id and use document.getElementBYId(id). Now you can identify click on every button that which one is clicked.

user3547883
  • 83
  • 3
  • 11