How to access anchor tag in code file in ASP.NET

September 11, 2013 0 Comments

The HtmlAnchor Class

The HtmlAnchor class is used to create an anchor, <a>, element for navigation. This class can be used for the following purpose:
Navigation- You can use the Href property and provide the address of anchor website, where you want to take the user . Alternatively , you can also take the user at a different location of the same page.
Handling events : You can handle the events of this class , such as the ServerClick event, to programmatically perform the desired actions, when user interacts with the anchor <a> element.
This HtmlAnchor class gives you access to the HTML <a> tag in server code.

Event of the HtmlAnchor Class

ServerClick : Occurs when the user clicks an Anchor control in the browser, This event is handled in the server.

Example of How to access anchor tag in code file in ASP.NET

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void anchor1_ServerClick(object sender, EventArgs e)
        anci.InnerHtml = " welcome to anchor tag";

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <a id="anchor1" runat ="server" onserverclick ="anchor1_ServerClick">Click here</a>
        <br />
        <span id="anci" runat ="server" ></span>
How to access anchor tag in code file in ASP.NET

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google