I want to set a public property in my code behind file, and then use that property to set the href property of several HtmlGenericControl <a>
tags. Here is what I've tried:
Code behind:
public partial class className: System.Web.UI.MasterPage
{
private string _linkValue = "";
public string linkValue {
get { return _linkValue; }
}
protected void Page_Load (object sender, EventArgs e)
{
SetLink();
}
private void SetLink()
{
_linkValue = "myUrl";
}
}
.aspx file
<ul>
<li><a runat="server" href="<%= linkValue %>">Link 1</a></li>
<li><a runat="server" href="<%= linkValue %>">Link 2</a></li>
<li><a runat="server" href="<%= linkValue %>">Link 3</a></li>
</ul>
Instead of the href being set to "myUrl", the href is %3C%25=%20linkValue%25%3E1
If that is all you want to do to those <a>
tags, you don't need to make them server-side controls. Get rid of the runat="server"
and it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With