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....

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 meeting, networking, learning, and sharing knowledge.