ASP. NET Ajax control development Basics

Source: Internet
Author: User

Javascript is missing in a widely used version. NET developers are familiar with several key concepts of OOP, while ASP. net AJAX can simulate most of them, and ASP. net Ajax is designed to use. some other structures (such as properties, events, enumerations, and interfaces) that are familiar to NET developers are converted to JavaScript. ASP. the reflection API in net Ajax checks all types (whether built-in type, class, interface, namespace, or even enumeration), and they include similar. net Framework functions (such as isinstanceoftype and inheritsfrom) can check the hierarchy of classes at runtime.

The following is a typical ajaxcontroltoolkit control script. The red part is the added explain statement:

// (C) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Permissive license.
// See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx.
// All other rights reserved.

Type. registernamespace ('ajaxcontroltoolkit '); // defines the namespace

// Define the class in ASP. NET Ajax. You need to assign the constructor to the variable (Note: how to call the basic function of the constructor ):

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
/// </Param>

// Call the initialization base class, similar to the C ++/C # base keyword
Ajaxcontroltoolkit. confirmbuttonbehavior. initializebase (this, [element]);

// Confirm text
This. _ confirmtextvalue = NULL;
// Click handler for the target control
This. _ clickhandler = NULL;
}

// Define a member through prototype ()
Ajaxcontroltoolkit. confirmbuttonbehavior. Prototype = {

// Initialize the resource
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 );
},

// Release resources

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 ');
}
}
}

// Final registration type:
Ajaxcontroltoolkit. confirmbuttonbehavior. registerclass ('ajaxcontroltoolkit. confirmbuttonbehavior ', ajaxcontroltoolkit. behaviorbase );

 

Reference: [ASP. NET Ajax] JavaScript extensions similar to the. NET Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.