Hi,

I want to generate an anchor tag

<a href="#" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>

in code behind using c#...but dunno how to do....

Recommended Answers

Add the namespace for HtmlAnchor (using System.Web.UI.HtmlControls;),

protected void Page_Load(object sender, EventArgs e)
    {
        HtmlAnchor htmlanchor = new HtmlAnchor();
        htmlanchor.HRef = "#";
        htmlanchor.Title = "Welcome"; //tooltip
        htmlanchor.InnerText = "Welcome";
        this.form1.Controls.Add(htmlanchor);
    }
Jump to Post

All 5 Replies

Add the namespace for HtmlAnchor (using System.Web.UI.HtmlControls;),

protected void Page_Load(object sender, EventArgs e)
    {
        HtmlAnchor htmlanchor = new HtmlAnchor();
        htmlanchor.HRef = "#";
        htmlanchor.Title = "Welcome"; //tooltip
        htmlanchor.InnerText = "Welcome";
        this.form1.Controls.Add(htmlanchor);
    }

Thanks Renu

And how do you associate it with an image?

how to add Onclick in ancher tag in html

(OR)

Dynamically add the Ancher Tag in asp.net means codebehind to add anchor tag in asp.net

how to add Onclick in ancher tag in html

htmlanchor.Attributes["onClick"] = "myOnClick();";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.