Call ASP.NET function from JavaScript?

后端 未结 20 2317
暗喜
暗喜 2020-11-22 07:21

I\'m writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event.

Is it possible to call a method I created in ASP with

20条回答
  •  半阙折子戏
    2020-11-22 08:10

    The __doPostBack() method works well.

    Another solution (very hackish) is to simply add an invisible ASP button in your markup and click it with a JavaScript method.

    From your JavaScript, retrieve the reference to the button using its ClientID and then call the .click() method on it.

    var button = document.getElementById(/* button client id */);
    
    button.click();
    

提交回复
热议问题