HtmlAnchor.OnServerClick Method
Raises the ServerClick event. This allows you to provide a custom handler for the event.
[Visual Basic] Protected Overridable Sub OnServerClick( _ ByVal e As EventArgs _ ) [C#] protected virtual void OnServerClick( EventArgs e ); [C++] protected: virtual void OnServerClick( EventArgs* e ); [JScript] protected function OnServerClick( e : EventArgs );
Parameters
- e
- A System.EventArgs that contains event data.
Remarks
The ServerClick event is raised when the HtmlAnchor control is clicked. This server event causes a roundtrip to occur from the client to the server and back.
Raising an event invokes the event handler through a delegate. For more information, see Raising an Event.
The OnServerClick method also allows derived classes to handle the event without attaching a delegate. This is the preferred technique for handling the event in a derived class.
Notes to Inheritors: When overriding OnServerClick in a derived class, be sure to call the base class's OnServerClick method so that registered delegates receive the event.
Example
[Visual Basic, C#, JScript] The following example demonstrates how to declaratively specify and code an event handler for the ServerClick event. When the HtmlAnchor control is clicked, a message is displayed.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub HtmlAnchor_Click(sender As Object, e As EventArgs) Message.InnerHtml = "Thank you for clicking the HtmlAnchor control." End Sub </script> </head> <body> <form runat="server"> <h3> HtmlAnchor ServerClick Event Example </h3> <a id="AnchorButton" OnServerClick="HtmlAnchor_Click" runat="server"> Click Here </a> <br><br> <span id="Message" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void HtmlAnchor_Click(Object sender, EventArgs e) { Message.InnerHtml = "Thank you for clicking the HtmlAnchor control."; } </script> </head> <body> <form runat="server"> <h3> HtmlAnchor ServerClick Event Example </h3> <a id="AnchorButton" OnServerClick="HtmlAnchor_Click" runat="server"> Click Here </a> <br><br> <span id="Message" runat="server"/> </form> </body> </html> [JScript] <%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function HtmlAnchor_Click(sender : Object, E : EventArgs) { Message.InnerHtml = "Thank you for clicking the HtmlAnchor control." } </script> </head> <body> <form runat="server"> <h3> HtmlAnchor ServerClick Event Example </h3> <a id="AnchorButton" OnServerClick="HtmlAnchor_Click" runat="server"> Click Here </a> <br><br> <span id="Message" runat="server"/> </form> </body> </html>
[Visual Basic, C#, JScript] The following example modifies the preceding example to programmatically specify and code an event handler for the ServerClick event.
[Visual Basic] <%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub Page_Load(sender As Object, e As EventArgs) ' Create an EventHandler delegate for the method you want to handle the event ' and then add it to the list of methods called when the event is raised. AddHandler AnchorButton.ServerClick, AddressOf HtmlAnchor_Click End Sub Sub HtmlAnchor_Click(sender As Object, e As EventArgs) Message.InnerHtml = "Thank you for clicking the HtmlAnchor control." End Sub </script> </head> <body> <form runat="server"> <h3> HtmlAnchor ServerClick Event Example </h3> <a id="AnchorButton" runat="server"> Click Here </a> <br><br> <span id="Message" runat="server"/> </form> </body> </html> [C#] <%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void Page_Load(Object sender, EventArgs e) { // Create an EventHandler delegate for the method you want to handle the event // and then add it to the list of methods called when the event is raised. AnchorButton.ServerClick += new System.EventHandler(this.HtmlAnchor_Click); } void HtmlAnchor_Click(Object sender, EventArgs e) { Message.InnerHtml = "Thank you for clicking the HtmlAnchor control."; } </script> </head> <body> <form runat="server"> <h3> HtmlAnchor ServerClick Event Example </h3> <a id="AnchorButton" runat="server"> Click Here </a> <br><br> <span id="Message" runat="server"/> </form> </body> </html>
[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
HtmlAnchor Class | HtmlAnchor Members | System.Web.UI.HtmlControls Namespace | HtmlForm | ServerClick