Rabu, 11 September 2013

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

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";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a id="anchor1" runat ="server" onserverclick ="anchor1_ServerClick">Click here</a>
        <br />
        <span id="anci" runat ="server" ></span>
    </div>
    </form>
</body>
</html>
Output
How to access anchor tag in code file in ASP.NET

Tidak ada komentar:

Posting Komentar