javascriptはasp.netの後置コードの方法を呼び出します.

5167 ワード

aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="PriceSystem_temp_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>

<script src="../js/jquery-1.5.1.min.js" type="text/javascript"></script>
   1:  
   2:  
   3: <script>
   4:     $(function() {
   5:         PageMethods.Hello("  ", function(e) {
   6:             alert(e);
   7:         });
   8:     })

 
cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Xml;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Data;
using System.Web.Services;

public partial class PriceSystem_temp_Default : PageBase
{
protected void Page_Load(object sender, EventArgs e)
{

}

[WebMethod(EnableSession = true)]
public static string Hello(string name)
{
return "hello," + name;
}
}
 
  ASP.NET AJAX    JavaScript         Web Service,    : 



1  Web Service           Web Service    [ScriptService]  ; 



2  Web Service              [WebMethod]  ; 



3      ScriptManager       Web Service   ; 



4         JavaScript     Web Service:

      [NameSpace].[ClassName].[MethodName](param1, param2,..., callbackFunction) 



5               ,                 。

  ASP.NET AJAX    JavaScript        ASP.NET      ,    : 



1          (public); 



2           (C#  static,VB.NET  Shared),       ; 



3       [WebMethod]  ; 



4     ScriptManager   EnablePageMethods     true; 



5         JavaScript         :

      PageMethods.[MethodName](param1, param2,..., callbackFunction); 



6               ,