Microsoft ASP. NET Ajax framework entry (4) subscribe to event processing functions and PASS Parameters

Source: Internet
Author: User
Vs2008, C #3.0

The previous article mentioned how to subscribe to event processing functions for the client element. This article describes how to transmit parameters while subscribing.

1. Use function. createdelegate (instance, Function Method) Function pageload () {

This . Username =   " Guozhijian " ;
This . Password =   " Pass " ;
VaR Delegate   = Function. createdelegate ( This , Btncommitclick );

This . Showalert = Function () {
Alert ("A");
}

SYS. UI. domevent. addhandler ($ Get ( " Btncommit " ), " Click " , Delegate );

}

Function btncommitclick (EVT) {
Alert (This. Username );
Alert (This. Password );
This. Showalert ();
}

When function. createdelegate is called, the first parameter uses the this keyword. In the delegate function, this keyword can be used to referenceCodeThe member of the object where the block is located (including attributes and methods ).

2. Use function. createcallback (function method, context) Function pageload () {

VaR Context =   {
Username:"Guozhijian",
Password:"Pass"
} ;
VaR callback = Function. createcallback (btncommitkeypress, context );

SYS. UI. domevent. addhandler ($ Get ( " Btncommit " ), " Keypress " , Callback );
}

Function btncommitkeypress (EVT, context) {
Alert (context. username );
Alert (context. Password );
}

When function. createcallback is called, the second parameter is used to pass an object defined in the scope of the subscription event processing method ).

Related Article

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.