Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If lblclick is a <code>Label</code>, then you can't add a asp tag like LinkButton just like that.</p> <p>If you can (or if you move the LinkButton to your markup) you need to add the <code>runat="server"</code> to be able to set properties like <code>CssClass</code> on it. If you just want a plain link you can add an anchor tag instead.</p> <pre><code>lblclick.Text = "&lt;p&gt;See what our page looks like by clicking &lt;a href=\"" + link + "\" class=\"linkclass\"&gt;" + link1 + "&lt;/a&gt;&lt;/p&gt;" </code></pre> <hr> <p>Actually, if you want a <em>link</em> to another page you shouldn't use LinkButton at all, but rather the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.aspx" rel="nofollow noreferrer">HyperLink class</a>. You can use the <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink.navigateurl.aspx" rel="nofollow noreferrer">NavigateUrl property</a> to set the url to open when clicking the link.</p> <p>If you want to add it to your markup you do it like this</p> <pre><code>&lt;asp:HyperLink NavigateUrl="http://www.example.com" CssClass="linkclass" Text="link1" runat="server" /&gt; </code></pre> <p>and if you want to do it dynamically in code you add it by creating it and adding it to your <code>Controls</code> collection.</p> <pre><code>HyperLink link = new HyperLink(); link.NavigateUrl = "http://www.example.com"; link.Text = "link1"; link.CssClass = "linkclass"; Controls.Add(link); </code></pre> <p>Just remember that when you add controls dynamically you should add it in your <code>Page_Load</code> event every time you load your page. If you don't want it to display set its <code>Visible</code> property to <code>false</code> and change it to <code>true</code> based on an event or something. Perhaps not as important when using a HyperLink, but good practice nonetheless. An example of when dynamic controls bite you if you don't is <a href="https://stackoverflow.com/questions/4145851/asp-net-c-creating-dynamicly-controls-handling-events">this question asked recently</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload