ASP.NET Syntax ASP.NET Page Syntax Page Directives
Indicates that the current page implements the specified .NET Framework interface.
<%@ Implements interface = "ValidInterfaceName" %>
interface |
The interface to be implemented on the page. |
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.
The below code snippet demonstrates a user control that includes an @ Implements directive to access to 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 Text property and Click event.
public String Text;
public event EventHandler Click;
// evaluates data binding expressions when 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>
<%@ Implements Interface = "System.Web.UI.IPostBackEventHandler" %>
<script language="VB" runat="server">
' defines Text property and Click event
Public Property Text As String
Public Event Click As EventHandler
' evaluates data binding expressions when 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> |
|
C# |
VB |
Web Forms Code Model