@ Implements
Indicates that the current page or user control implements the specified .NET Framework interface.
<%@ Implements interface="ValidInterfaceName" %>
Attributes
- interface
The interface to be implemented on the page or user control.
Remarks
When you implement an interface in a Web Forms page, you can declare its events, methods, and properties between opening and closing tags of a <script> element in a code declaration block. You cannot use this directive to implement an interface in a code-behind file.
Example
The following example demonstrates a user control that includes an @ Implements directive to access the properties and methods of the IPostBackEventHandler interface. To use this sample, include it in a .ascx file, then declare the user control in a Web Forms page (an .aspx file). For more information on how to include a user control in a Web Forms page, see the following topics: @ Register, Custom Server Control Syntax, and Including a User Control in a Web Forms Page.
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
<script language="C#" runat="server">
//Defines the Text property and the Click event.
public String Text;
public event EventHandler Click;
//Evaluates data-binding expressions when the page is loaded.
void Page_Load (Object sender, EventArgs e) {
this.DataBind();
}
//Implementation of the event.
public virtual void RaisePostBackEvent(string eventArgument) {
OnClick(new EventArgs());
}
protected virtual void OnClick(EventArgs e) {
if (Click!= null) {
Click(this,e);
}
}
</script>
<a href=<%# String.Format("javascript:{0}", Page.GetPostBackEventReference(this)) %>>
<asp:Label id=l1 Text='<%# Text%>' runat="server"/>
</a>
[Visual Basic]
<%@ Implements Interface="System.Web.UI.IPostBackEventHandler" %>
<script language="VB" runat="server">
'Defines the Text property and the Click event.
Public Property Text As String
Public Event Click As EventHandler
'Evaluates data-binding expressions when the page is loaded.
Sub Page_Load (Sender As Object, e As EventArgs) {
Me.DataBind()
End Sub
'Implementation of the event.
Public Sub RaisePostBackEvent(eventArgument As String) _
Implements IPostBackEventHandler.RaisePostBackEvent
OnClick(New EventArgs())
End Sub
Protected Overridable Sub OnClick(e As EventArgs) {
RaiseEvent Click(Me, e)
End Sub
</script>
<a href=<%# String.Format("javascript:{0}", Page.GetPostBackEventReference(Me)) %>>
<asp:Label id=l1 Text='<%# Text%>' runat="server"/>
</a>
See Also
ASP.NET Web Forms Syntax | Directive Syntax | Web Forms Code Model