2

how to automatically click a html button when asp.net button is clicked. I want when I click btn then automatically Button1 which is a html button is clicked and performs the task... that means by pressing one button it internally works for two buttons

0

4 Answers 4

2

Attach the onclick event in the markup of the ASPX page (on the button):

onclick="#('elementName').click();"

Now, if you don't want the post back to occur on the ASP.NET button, then do this:

onclick="#('elementName').click(); return false;"
Sign up to request clarification or add additional context in comments.

Comments

1

In the asp button, add a OnClientClick event to call a javascript function and then trigger the second button click from within.

<asp:Button Text="Server Button" runat="server" OnClientClick="js_function();"/>
<input type="button" id="inpbutton" value="Client Button"/>

function js_function()
{
    $("#inpbutton").trigger("click");
}

Comments

0

This should do it. Update the selectors with the ones in your page

<script>
    $('#<%=ASPBUTTON.ClientID %>').click(function(event)
    {
        $('OTHER BUTTON ELEMENT SELECTOR').click();
        event.preventDefault();
        return false;
    });
</script>

Comments

0

You can do this in two way.

first by using common class name for both button

<button name='cmd1' class='cmd' >button 1</button>
 <button name='cmd2' class='cmd' >button 2</button>

jQuery

//common click event for both button
$('.cmd').bind('click', function(){
  ...
  ...
});

and for second method you can create two seprate onclick function for both button , when a button get click (source) inside that function call target function , like this

<button name='cmd1' onclick='first_function()' >button 1</button>
<button name='cmd2' onclick='second_function()' >button 2</button>

Javascript

function first_function(){
     // call second function
     second_function();
     ...
     ...
    }

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.