DOT NET 4.0 – Directives for Web Forms Pages – @ Implements [Visual Basic] Directives

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 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: @ RegisterCustom Server Control Syntax, and Including a User Control in a Web Forms Page.

[C#]

<%@ 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>

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 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>

javascript:{0}”, Page.GetPostBackEventReference(Me)) %>>

<asp:Label id=l1 Text='<%# Text%>’ runat=”server”/>

</a>

Reference : Dilip Kumar Jena ( https://mstechexplore.wordpress.com )


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s