Home > Web Front-end > JS Tutorial > The simplest way to call ASP.NET server-side methods from JavaScript

The simplest way to call ASP.NET server-side methods from JavaScript

高洛峰
Release: 2016-11-25 10:53:37
Original
1633 people have browsed it

对于这样的问题,有很多解决方法,如果你返回的内容是简单的内容,如注册用户时候的验证信息,只需返回存在与否,那么可以采用下面最最简单的代码实现:

C# 代码
<%@ Page Language="C#" %>

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



 
 


 


 
 
 



If you need to return complex objects, you need to serialize the objects. You can take the following simple method. When using this method, you need to pay attention to the following three points:
1. The background method must be marked with the [System.Web.Services.WebMethod] attribute;
2. The background method must be a static method of static type;
3. ScriptManager must be set with EnablePageMethods=" true".

ASPX Code
<%@ Page Language="C#" %>

"http://www.w3 .org/TR/xhtml1/DTD/xhtml1-transitional.dtd">







 


 
 
 
 
 

 


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template