Iwebpartparameters makes connection between Web parts easy-csdn Chen Liang

Source: Internet
Author: User

Http://blog.csdn.net/savage54321/archive/2008/01/14/2043216.aspx

 

If Google the key words like: Web part, connection or communication, we can get a bunch of results. I have to say all articles are the same and the authors talk about how to do it like a professor in the college. the only difference you can find is that the approach to implement and design an interface that makes 2 Web parts connects to each other; meanwhile, those guys talk about the benefit we ca N get if we use the interface. But, do we really necessarily to do it like that? I mean, do we really need to implement or design an interface ourselves? Too should interfaces make the system hard to understand and maintain. Can we just use an universal one to keep the pain?
Actually, in. NET 2.0, Microsoft providers a standard the iwebparameters to be the communication interface. however, there're few people know, I mean in China, how to use it. even some Chinese MVPs of Microsoft are using the interfaces which they define. they're all warriors; they have no idea about how much impact the book they wrote can bring to those innocent fresh men. stop it, stop being buffing and sit down to learn some new things.
As we known, the key of communication of Web part is some sort of consumer and provider mode. and the interface between them is the bridge. i'll tell you how to use the iwebparameters to be the bridge.
First the provider Web part needs to implement the iwebpartparameters:

Public   Class Seachform: system. Web. UI. webcontrols. webparts. webpart, iwebpartparameters
// Within the class, you need to some method and property of the iwebpartparameters:

Private Propertydescriptorcollection _ PD;
[Connectionprovider ( " Parameters " )]
Public Iwebpartparameters connectioninterface ()
... {
Return This;
}

Public   Void Getparametersdata (parameterscallback callback)
... {
Idictionary DIC= NewHashtable ();
Callback. Invoke (DIC );
//Callback. begininvoke (DIC );
}

Public Propertydescriptorcollection Schema
... {
Set   ... {_ PD=Value ;}
Get   ... {Return_ PD ;}
}
Public   Void Setconsumerschema (propertydescriptorcollection schema)
... {
_ PD=Schema;
}

Within the class, you need to implement some method and property of the iwebpartparameters:

Public iwebpartparameters connectioninterface (). The method wocould be invoked by consumer, the purpose of the method is to pass the reference of the iwebparameters to the consumer.

Public void getparametersdata (parameterscallback callback ). key method, the remote method within the consumer wocould be passed in by the parameterscallback. and you can invoke the peer method by make some callings to the callback, like following. BTW, all parameters was passes by a standard interface 'idictionary '.

Public propertydescriptorcollection schema. you have to implement the property, even if you don't like it, 'cause it's part of the interface iwebparameters.

Public void setconsumerschema (propertydescriptorcollection schema ). the method wocould be invoked by consumer. consumer passes the propertydescriptorcollection to the provider by calling the method.

heres 'The consumer:

[Connectionconsumer ( " Parameters " )]
Public   Void Getconnectioninterface (iwebpartparameters providerpart)
... {
Propertydescriptor [] property =   ... {Typedescriptor. getproperties (This)["_ Sdbalias"]} ;
Propertydescriptorcollection Schema =   New Propertydescriptorcollection (property );
Providerpart. setconsumerschema (schema );
Parameterscallback callback =   New Parameterscallback (receiveparameters );
Providerpart. getparametersdata (callback );
}

Public   Void Receiveparameters (idictionary Params)
... {
//Implement all your logic
}

 

And then, all the stories are the same, put 2 Web part into the same web page, make they connect to each other in editable mode.

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.