Turn: about Web Part Communication

Source: Internet
Author: User

 

Reference: http://zmsx.cnblogs.com/archive/2005/12/21/301994.html

 

Web Part communication web part is a new feature provided in Asp.net 2.0, through which end users can freely modify the page layout, the effect can look at Google Custom page http://www.google.com/ig? Hl = ZH-CN, which is also very simple to use. Next we will talk about the two Web Part communication experiences. Web Part communication is managed by webpartmanager. 1. Define a public interface for communication. 2. Webpartmanager obtains the interface through the publisher. 3. Webpartmanager sends an interface to the subscriber. I did an experiment on getting a date through the calendar control and passing it to textbox in another Web part, where something went wrong. First look at the interface code using system; using system. data; public interface iselecteddate {datetime selecteddate ();} as an excuse provider, you must first implement the interface and mark it through [connectionprovider ("iselecteddate", "dateinfoprovider. In connectionprovider, the first parameter is the interface name, and the last parameter is the passed parameter. The Code is as follows: public partial class calendaruc: system. web. UI. usercontrol, iselecteddate {datetime _ dateinfo = datetime. now; [personalizable] public datetime dateinfo {get {return _ dateinfo;} set {_ dateinfo = value ;}} [connectionprovider ("iselecteddate", "dateinfoprovider")] public iselecteddate getdate () {return this;} public datetime selecteddate () {return _ dateinfo;} protected void calendar1_s Electionchanged (Object sender, eventargs e) {_ dateinfo = This. calendar1.selecteddate;} protected void page_load (Object sender, eventargs e) {}} then the message subscriber should use the message. It needs to use the [connectionconsumer ("iselecteddate", "dateinfoconsumer")] mark. The Code is as follows: public partial class Google: system. web. UI. usercontrol {protected void page_load (Object sender, eventargs e) {} protected void button#click (Object sender, eventargs e) {response. write (page. isvalid); string querystr = httputility. urlencode (textbox1.text); response. redirect (@ "http://www.google.com/search? Q = "+ querystr);} [connectionconsumer (" iselecteddate "," dateinfoconsumer ")] public void getdate (iselecteddate searchtext) {textbox1.text = searchtext. selecteddate (). tostring () ;}} finally sets the webpartmanager attribute to establish a static connection. Finally, modify the following code to set the displaymode of webpartmanager to webpartmanager. connectdisplaymode. Theoretically, if the above steps are completed, the establishment of static communication should be completed, but the following error will be reported after running. The specified display mode is not supported on this page. make sure personalization is enabled and the corresponding zones are present on the page. the display mode can be set during and after page_init. parameter Name: value can solve this problem by adding a connectionzone control on the page. However, after this operation, the end user will see this connectionzone control. There is always a better solution, the connection can be established completely through the Code. If you have any good solutions, please let me know.

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.