Reputation: 47
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
Upvotes: 2
Views: 4371
Reputation: 549
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");
}
Upvotes: 1
Reputation: 835
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();
...
...
}
Upvotes: 0
Reputation: 3035
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>
Upvotes: 0
Reputation: 67898
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;"
Upvotes: 2