ASP.NET AJAX 控件开发基础

简介:
在 JavaScript 当前广泛使用的版本中,它缺少 .NET 开发人员所熟悉的几个 OOP 的关键概念,而 ASP.NET AJAX 可以模拟其中的大多数,而且 ASP.NET AJAX 的目标是将使用 .NET 的开发人员所熟悉的某些其他构造(例如属性、事件、枚举和接口)转换成 JavaScript.ASP.NET AJAX 中的反射 API 将检查所有类型(无论是内置类型、类、接口、命名空间、或者甚至是枚举),而它们包括的类似 .NET Framework 的函数(例如 isInstanceOfType 和 inheritsFrom)可以在运行时检查类的层次结构。
下面是一个典型的AjaxControlToolkit的控件脚本,红色部分为添加的解释语句:
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive License.
// See  [url]http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx[/url].
// All other rights reserved.
Type.registerNamespace('AjaxControlToolkit');    //定义命名空间
//在 ASP.NET AJAX 中定义类,您需要将其构造函数赋给变量(注意,构造函数如何调用基础函数):
AjaxControlToolkit.ConfirmButtonBehavior = function(element) {
/// <summary>
/// The ConfirmButtonBehavior extends buttons by providing a confirmation dialog when clicked
/// </summary>
/// <param name="element" type="Sys.UI.DomElement" domElement="true">
/// Button the behavior is associated with
/// </param>
//调用初始化基类,类似于C++/C# base关键字
AjaxControlToolkit.ConfirmButtonBehavior.initializeBase(this, [element]);
// Confirm text
this._ConfirmTextValue = null;
// Click handler for the target control
this._clickHandler = null;
}
//通过prototype定义成员()
AjaxControlToolkit.ConfirmButtonBehavior.prototype = {
//初始化资源
initialize : function() {
/// <summary>
/// Initialize the behavior
/// </summary>
AjaxControlToolkit.ConfirmButtonBehavior.callBaseMethod(this, 'initialize');
// Attach the handler
this._clickHandler = Function.createDelegate(this, this._onClick);
$addHandler(this.get_element(), "click", this._clickHandler); 
},
//释放资源
dispose : function() {
/// <summary>
/// Dispose the behavior
/// </summary>
// Detach event handlers
if (this._clickHandler) {
$removeHandler(this.get_element(), "click", this._clickHandler);
this._clickHandler = null;
}
AjaxControlToolkit.ConfirmButtonBehavior.callBaseMethod(this, 'dispose');
},
_onClick : function(e) {
/// <summary>
/// Button's click handler to display the confirmation dialog
/// </summary>
/// <param name="e" type="Sys.UI.DomEvent">
/// Event info
/// </param>
if (this.get_element() && !this.get_element().disabled) {
// Display confirm dialog and return result to allow cancellation
if (!window.confirm(this._ConfirmTextValue)) {
e.preventDefault();
return false;

}
},
get_ConfirmText : function() {
/// <value type="String">
/// The text to show when you want to confirm the click. (Note: HTML entities can be used here (ex: "&#10;" for new-line))
/// </value>
return this._ConfirmTextValue;
},
set_ConfirmText : function(value) {
if (this._ConfirmTextValue != value) {
this._ConfirmTextValue = value;
this.raisePropertyChanged('ConfirmText');
}
}
}
//最终注册类:
AjaxControlToolkit.ConfirmButtonBehavior.registerClass('AjaxControlToolkit.ConfirmButtonBehavior', AjaxControlToolkit.BehaviorBase);





本文转自 张善友 51CTO博客,原文链接:http://blog.51cto.com/shanyou/74291,如需转载请自行联系原作者
目录
相关文章
|
1月前
|
SQL 开发框架 数据可视化
企业应用开发中.NET EF常用哪种模式?
企业应用开发中.NET EF常用哪种模式?
|
2月前
|
开发框架 JavaScript 前端开发
5个.NET开源且强大的快速开发框架(帮助你提高生产效率)
5个.NET开源且强大的快速开发框架(帮助你提高生产效率)
|
4月前
|
SQL 开发框架 数据可视化
企业应用开发中.NET EF常用哪种模式?
企业应用开发中.NET EF常用哪种模式?
|
11天前
|
开发框架 前端开发 JavaScript
采用C#.Net +JavaScript 开发的云LIS系统源码 二级医院应用案例有演示
技术架构:Asp.NET CORE 3.1 MVC + SQLserver + Redis等 开发语言:C# 6.0、JavaScript 前端框架:JQuery、EasyUI、Bootstrap 后端框架:MVC、SQLSugar等 数 据 库:SQLserver 2012
|
1月前
|
数据安全/隐私保护 Windows
.net三层架构开发步骤
.net三层架构开发步骤
13 0
|
1月前
深入.net平台的分层开发
深入.net平台的分层开发
63 0
|
2月前
|
开发框架 前端开发 .NET
福利来袭,.NET Core开发5大案例,30w字PDF文档大放送!!!
为了便于大家查找,特将之前开发的.Net Core相关的五大案例整理成文,共计440页,32w字,免费提供给大家,文章底部有PDF下载链接。
36 1
福利来袭,.NET Core开发5大案例,30w字PDF文档大放送!!!
|
2月前
|
SQL 开发框架 前端开发
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
ASP.NET WEB项目中GridView与Repeater数据绑定控件的用法
34 0
|
3月前
|
C#
.NET开发中合理使用对象映射库,简化和提高工作效率
.NET开发中合理使用对象映射库,简化和提高工作效率
|
3月前
|
开发框架 前端开发 JavaScript
一款基于.NET Core的快速开发框架、支持多种前端UI、内置代码生成器
一款基于.NET Core的快速开发框架、支持多种前端UI、内置代码生成器
100 0