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
4 Answers
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
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();
...
...
}