0

How to determine which serverside Button click in Client Side javascript? There are many Buttons in the form.

      function onMyClicked()
      {
        var btn = ??;
        if (btn == 'IDDelete') {
        var result = confirm("........ ");
        if (result){       
        xxxxx
        }
        else close();
        }
        else if(btn=='IDClose'){
        xxxxx
        }

         window.onunload = function (){
         onMyClicked();
   }

    <asp:Button ID="IDDelete" runat="server" Text="Delete" --->
    <asp:Button ID="IDClose" runat="server" Text="Close" ---->

EDIT:

var isDirty;
        isDirty = 0;        
        function setDirty() {
            isDirty = 1;
        }        
        function onMyClicked() {
        var btn =???;
        if (btn == 'IDClose') {       
                var sSave;
                if (isDirty == 1) {            
                    sSave = window.returnValue = confirm('------');                    
                    if (window.returnValue == false) closerel();
                    if (sSave == true) {                    
                        document.getElementById('__EVENTTARGET').value = 'IDSave';
                        document.getElementById('__EVENTARGUMENT').value = 'Click';  
                        window.document.form1.submit();                        
                    }
                    else {                                 
                          close();                     
                    }
                }
                else close();
          }            
        }       
 window.onunload = function (){
         onMyClicked();
   }     

<asp:Button ID="IDDelete" runat="server" Text="Delete" >
<asp:Button ID="IDClose" runat="server" Text="Close" >
<asp:Button ID="IDSave" runat="server" Text="Save" >
<asp:Button ID="IDClose" runat="server" Text="Close" >

How to determinde IDClose click?

1
  • I hope you understand your client event fire before server ones do? Commented Dec 15, 2009 at 12:38

1 Answer 1

1

If you use OnClientClick property of the button, the function you type in the property runs. So your code will become:

function delete()
{
    var result = confirm("........ ");
    if (result){       
    xxxxx
    }
    else close();
    }
}

function close()
{
    xxxxx
}

<asp:Button ID="IDDelete" runat="server" Text="Delete" OnClientClick="Delete">
<asp:Button ID="IDClose" runat="server" Text="Close" OnClientClick="Close">
Sign up to request clarification or add additional context in comments.

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.