O'Reilly logo

ASP.NET 2.0: A Developer's Notebook by Wei-Meng Lee

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Enable Web Parts to Talk to Each Other

Note

Learn how the various Web Parts on a page can communicate with each other.

The various Web Parts on a page are not standalone islands of information. You can enable them to talk to each other by connecting them. This is useful in cases where you need to pass information obtained from one Web Part to another. For example, you may enter a Zip Code to obtain address information in a Web Part. The same Zip Code may be sent to another Web Part so that it can retrieve weather information.

How do I do that?

To illustrate how two Web Parts can be connected, you will first create a new Web User control that contains a Calendar control. When the user clicks a date in the Calendar control, the date selected will be sent to and displayed by the text box in the Google Web User control that you created in the lab.

  1. Using the project created in the previous lab (C:\ASPNET20\chap03-Webparts), add a new class to the project (right-click the project name in Solution Explorer and select Add New Item..., then select Class) and name it ISelectedDate.vb.

  2. Code the ISelectedDate.vb class as follows. The ISelectedDate interface would be implemented by both the connection provider (the CalendarUC.ascx) and provider consumer (Google.ascx). This interface serves as a contract for the communication between the provider and consumer:

    Imports Microsoft.VisualBasic
    
    Public Interface ISelectedDate
        ReadOnly Property SelectedDate( ) As Date
    End Interface
  3. Add a new Web User control ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required