当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > VS2008与.NET 3.5的JS智能感知和调试

ASP.NET
为T-SQL添加intellisense功能
SQL Server 2005安装过程中出现错误的解决办法
SQL Server 2005 RTM 安装错误 :The SQL Server System Configuration Checker cannot be executed due to
有关于JSON的一些资料
不能忽略c#中的using和as操作符的用处
JavaScript系列之―同步还是异步?
获取远程网页的内容之一(downmoon原创)
获取远程网页的内容之二(downmoon原创)
ASP.Net中防止刷新自动触发事件的解决方案
asp.net下用js实现鼠标移至小图,自动显示相应大图
Asp.Net 和 AJAX.Net 的区别
提交页面的定位--scrollIntoView的用法
利用AJAX与数据岛实现无刷新绑定
asp.net下判断用户什么时候离开,以什么方式离开
DataSet 添加数据集、行、列、主键和外键等操作示例
读写xml所有节点个人小结 和 读取xml节点的数据总结
收藏的asp.net文件上传类源码
asp.net下GDI+的一些常用应用(水印,文字,圆角处理)技巧
一个可以让.net程序在非WIN平台上运行的软件Mono
使用ASP.NET 2.0 CSS 控件适配器生成CSS友好的HTML输出

ASP.NET 中的 VS2008与.NET 3.5的JS智能感知和调试


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-28   浏览: 155 ::
收藏到网摘: n/a

  VS 2008可以非常完美地支持JavaScript和ASP.NET AJAX的智能感知和调试。.NET 3.5内置了ASP.NET AJAX,并且UpdatePanel终于可以支持WebPart了。

  示例

  Feature.js(被aspx页引用的js文件)

以下为引用的内容:
  // 创建一个math类
  window.math = function()
  {
  /// 数学函数类
  }
  
  window.math.prototype =
  {
   // 为math类创建一个max方法
   max: function(x, y)
   {
   /// 返回两个整数中的最大的一个
   /// 需要比较的第一个整数
   /// 需要比较的第二个整数
  
   if (x > y)
   return x;
   else
   return y;
   }
  } 

  Feature2.js(在js文件中智能感知外部js文件的JavaScript和ASP.NET AJAX)

以下为引用的内容:

  ///  
  ///  
   
  // 外部js文件用这种方法引进来 
  // 控件引入的js用这种方法引进来 
   
  function refTest() 
  { 
   // 因为有了“”,所以会感知到Feature.js提供的JavaScript 
   var m = new window.math(); 
   
   var v = m.max(x, y); 
   
   // 因为有了“”,所以会感知到ASP.NET AJAX 
   // $get("testIntellisense"); 
  }

  WebServiceMath.asmx(为ASP.NET AJAX提供服务的WebService)
  
<%@ WebService Language="C#" Class="WebServiceMath" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Description = "WebService提供的数学函数类", Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebServiceMath : System.Web.Services.WebService
{
    /// <summary>
    /// 返回两个整数中的最大的一个
    /// </summary>
    /// <param name="x">需要比较的第一个整数</param>
    /// <param name="y">需要比较的第二个整数</param>
    /// <returns></returns>
    [WebMethod(Description = "返回两个整数中的最大的一个")]
    public int Max(int x, int y)
    {
        if (x > y)
            return x;
        else
            return y;
    }
}

  JavaScript.aspx
  

以下为引用的内容:
<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="JavaScript.aspx.cs"
    Inherits="Feature_JavaScript" Title="JavaScript的智能感知和调试(JavaScript Intellisense and Debugging)" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">

    <script src="../JS/Feature.js" type="text/javascript"></script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="width: 600px">
        VS 2008可以非常完美地支持JavaScript和ASP.NET AJAX的智能感知和调试。.NET 3.5内置了ASP.NET AJAX,并且UpdatePanel终于可以支持WebPart了。
    </div>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        <Services>
            <asp:ServiceReference Path="WebServiceMath.asmx" />
        </Services>
    </asp:ScriptManager>

    <script type="text/javascript">
        
        var x, y;
        x = 100;
        y = 101

        // 新建一个math对象
        // 此处输入任意字母,就会出现JavaScript的智能感知
        // 输入window.就会感知到Feature.js文件里创建的math类,并提示math类的summary - 数学函数类
        var m = new window.math();
    
        // 取x,y之间的最大值
        // 输入m.就会感知到math对象的max方法,并提示max方法的summary - 返回两个整数中的最大的一个
        // 输入max方法的参数的时候,会提示两个参数的说明 - 需要比较的第一个整数;需要比较的第二个整数
        var v = m.max(x, y);
        
        alert(v);
        
        // 可以在任意JavaScript语句处插入断点,然后就可以对JavaScript进行调试
    
        // ASP.NET AJAX调用web service
        // WebServiceMath会被智能感知出来
        // 输入WebServiceMath.后,就会感知到Max方法
        // 输入Max方法后,就会有参数提示 - x, y, onSuccess, onFailed, userContext
        WebServiceMath.Max(x, y, onSuccess);
        
        function onSuccess(result)
        {
            alert(result);
        }