Is it possible to call ASP.NET codebehind function from JavaScript.
The Code Behind function can be called from Client Side (JavaScript) using ASP.Net AJAX PageMethods in ASP.Net. The first thing you need to do is add a ASP.Net AJAX ScriptManager to the page and set its EnablePageMethods property to true.
NET code can do virtually anything when combined with HTML and CSS but JavaScript is still very important and the reason lies in the different domains in which each language operates.
In order to call the JavaScript function with parameter from Code Behind, one has to make use of the RegisterStartupScript method of the ClientScript class in ASP.Net using C# and VB.Net. The following HTML Markup consists of an ASP.Net Button and a Label control.
yes, you can make web method like..
<WebMethod(EnableSession:=True), ScriptMethod()> _
Public Shared Function updateContent() As String
Return "Your String"
End Function
and then call in javascript like..
PageMethods.updateTabContent(parameterValueIfAny, onSuccessMethod,onFailMethod);
this also need to add
<asp:ScriptManager ID="ScriptMgr" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With