I have a question, I have a button like below:
<asp:Button ID="savebtn" runat="server" OnClick="savebtn_Click" Visible="false" />
I then have HTML button like like below:
<button id="btnsave" onclick="fncsave">Save</button>
I have the javascript below:
<script type="text/javascript">
function fncsave()
{
document.getElementById('<%= savebtn.OnClick %>').click()
}
</script>
My question now is, how can I call the asp:Button OnClick from the HTML button? I have read you can do this by calling from JavaScript by Id but is not working.
Any help will be really appreciate it.
Thank you
This question is related to
javascript
asp.net
html
.net
If you're open to using jQuery:
<script type="text/javascript">
function fncsave()
{
$('#<%= savebtn.ClientID %>').click();
}
</script>
Also, if you are using .NET 4 or better you can make the ClientIDMode == static
and simplify the code:
<script type="text/javascript">
function fncsave()
{
$("#savebtn").click();
}
</script>
Reference: MSDN Article for Control.ClientIDMode
Source: Stackoverflow.com