@ Implements
Indicates that the current ASP.NET application file (Web page, user control, or master page) implements the specified .NET Framework interface.
<%@ Implements interface="ValidInterfaceName" %>
The following code example demonstrates a user control that includes an @ Implements directive to access the six properties of the IWebPart interface. By implementing these properties in the user control, you enable the user control to have the properties and appearance of a WebPart control, when you place it within a WebPartZone control. The first part of the code example is the user control; place this code in a file and name it CalendarUserControl.ascx.
The second part of the code example is a page to host the user control. Note that the page uses an @ Register directive to register the user control for use on the page. Notice also that, when the user control is declared in the body of the page, some IWebPart properties such as Title and Description are assigned values in the declarative syntax. For more information on how to include a user control in a Web Forms page, see @ Register, Custom Server Control Syntax, and How to: Include a User Control in an ASP.NET Web Page. For information about Web Parts pages, see ASP.NET Web Parts Pages.
<!-- A user control that implements an interface. --> <%@ Control language="VB" ClassName="CalendarUserControl" %> <%@ implements interface="System.Web.UI.WebControls.WebParts.IWebPart" %> <script runat="server"> Private m_Description As String Private m_Title As String Private m_TitleIconImageUrl As String Private m_TitleUrl As String Private m_CatalogIconImageUrl As String <Personalizable()> _ Public Property Description() As String _ Implements IWebPart.Description Get Dim objTitle As Object = ViewState("Description") If objTitle Is Nothing Then Return String.Empty End If Return CStr(objTitle) End Get Set(ByVal value As String) ViewState("Description") = Server.HtmlEncode(value) End Set End Property <Personalizable()> _ Public Property Title() As String _ Implements IWebPart.Title Get Dim objTitle As Object = ViewState("Title") If objTitle Is Nothing Then Return String.Empty End If Return CStr(objTitle) End Get Set(ByVal value As String) ViewState("Title") = Server.HtmlEncode(value) End Set End Property ReadOnly Property Subtitle() As String _ Implements IWebPart.Subtitle Get Dim objSubTitle As Object = ViewState("Subtitle") If objSubTitle Is Nothing Then Return "Acme Corp" End If Return CStr(objSubTitle) End Get End Property <Personalizable()> _ Public Property TitleIconImageUrl() As String _ Implements IWebPart.TitleIconImageUrl Get Dim objTitle As Object = ViewState("TitleIconImageUrl") If objTitle Is Nothing Then Return String.Empty End If Return CStr(objTitle) End Get Set(ByVal value As String) ViewState("TitleIconImageUrl") = Server.HtmlEncode(value) End Set End Property <Personalizable()> _ Public Property TitleUrl() As String _ Implements IWebPart.TitleUrl Get Dim objTitle As Object = ViewState("TitleUrl") If objTitle Is Nothing Then Return String.Empty End If Return CStr(objTitle) End Get Set(ByVal value As String) ViewState("TitleUrl") = Server.HtmlEncode(value) End Set End Property <Personalizable()> _ Public Property CatalogIconImageUrl() As String _ Implements IWebPart.CatalogIconImageUrl Get Dim objTitle As Object = ViewState("CatalogIconImageUrl") If objTitle Is Nothing Then Return String.Empty End If Return CStr(objTitle) End Get Set(ByVal value As String) ViewState("CatalogIconImageUrl") = Server.HtmlEncode(value) End Set End Property </script> <asp:calendar id="Calendar1" runat="server" /> <!-- A page that registers and hosts the user control. --> <%@ Page language="VB" %> <%@ register tagprefix="uc1" tagname="CalControl" src="~/CalendarUserControl.ascx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head id="Head1" runat="server"> <title>Calendar Page</title> </head> <body> <form id="form1" runat="server"> <asp:webpartmanager id="manager1" runat="server" /> <asp:webpartzone id="WebPartZone1" runat="server"> <zonetemplate> <uc1:CalControl id="CalControl1" runat="server" title="Personal Calendar" description="My personal calendar for work." /> </zonetemplate> </asp:webpartzone> </form> </body> </html>