Export (0) Print
Expand All

HtmlAnchor.ServerClick Event

Occurs when the HtmlAnchor control is clicked.

[Visual Basic]
Public Event ServerClick As EventHandler
[C#]
public event EventHandler ServerClick;
[C++]
public: __event EventHandler* ServerClick;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

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.

For more information about handling events, see Consuming Events.

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 previous 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 Language Filter 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 | OnServerClick

Show:
© 2014 Microsoft