I have a JavaScript function that is triggered by the click event of an HTML button on an ASPX page. Additionally, there is a server method located in the code-behind page for handling this functionality. My goal is to invoke the server method from the JavaScript function with specific parameters only when the user clicks the HTML button.
It is important to adhere to this scenario without incorporating any asp.net controls in the aspx page. The use of only HTML controls must be maintained. Can someone assist me with achieving this?
Below is the provided code snippet:
Code in markup:
<script language="javascript" type="text/javascript">
function btnAccept_onclick() {
var name;
name = document.getElementById('txtName').value;
// Call Server side method SetName() by passing this parameter 'name'
</script>
<input type="button" id="btnAccept" value="Accept" onclick="return btnAccept_onclick()" />
Code-behind:
public void SetName(string name)
{
// Code for some functionality
}