ASP. NET custom server control internal details series tutorial 5

Source: Internet
Author: User

If you want to reprint it, Please retain your copyright:
/*
* Description: ASP. NET custom server control internal details series tutorial
* Auther: chongchong-innocent haoban
* MSN: chongchong2008@msn.com
* Dates: 2007-05-20
* Copyright: chongchong2008 Yichang Hubei China
*/

5 Server Control return Architecture

There are two important interfaces for the callback architecture: ipostbackeventhandler and ipostbackdatahandler.
The ipostbackeventhandler interface causes the control to trigger an event that indicates that a callback has occurred.
The ipostbackdatahandler interface allows the control to retrieve the transmitted form data, update the status accordingly, and then trigger events on the server to indicate the status changes.

1. Ipostbackeventhandler
1.1 map a callback event to a server event
Public interface ipostbackeventhandler
{
Void raisepostbackevent (string eventarguments );
}
The eventarguments parameter is used to identify and trigger different events if the control generates multiple HTML tags that can cause the return event.

1.2 generate the client script for return
If you want to use a hyperlink to cause a callback, you also need to implement the ipostbackeventhandler interface first, and then use the following method:
Page. getpostbackclienthyperlink (object, string );

Getpostbackclienthyperlink provides the following functions:
First, return a string "javascript :__ dopostback ('youcontroluniqueid','') ", which includes a call to the _ dopostback JavaScript function generated by the page framework.
Second, tell the page to generate two hidden domains (_ eventtarget and _ eventargument), and a JavaScript function that causes the return (____ dopostback.

2. Ipostbackdatahandler
The ipostbackdatahandler interface must be implemented to participate in data return processing. It has two methods on the right.
Public interface ipostbackdatahandler
{
Bool loadpostdate (string postdatekey, namevaluecollection postcollection );
Void raisepostdatechangedevent ();
}

In the loading and returning data stage, you can view every name in the name/value form transfer set and find the uniqueid control that matches the name in the control tree. If the page finds such a control and implements ipostbackdatahandler, the page calls loadpostdata on this control.

The loadpostdata method has two parameters: a string containing the name of the returned element and a system. Collections. Specialized. namevaluecollection instance containing the name/value set of the transmitted form data. You can use the return data to update its status.
If the control status changes when it is returned, and you want to trigger an event to mark this change, you must return the true value from the loadpostdata method.
When the loadpostdata method of the control returns true, the page calls the raisepostdatechangedevent method of the control.

 

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.