How to call an asp.net function from JavaScript

{0 Comments}

In this article we will see how we can call a server side method using JavaScript using simple trick. For this, first we add a button on the web form, and then double click on the button to generate a page method for that button. So now to hide the button set its style property to display:none so that it will not be visible. Then we will create a JavaScript function to call the button click event using JavaScript. Then finally call the JavaScript function any where, here I have used a link to call the same button click event using JavaScript.

Syntax for the asp button with the style property set to display none is as follows:

Then here is the function which will call the button click function. By finding the id of the button.

function CallButtonClick() { document.getElementById('Button1').click(); }

This link will call the JavaScript function.   

 

Call Server Function


Leave a Comment

Your email address will not be published.