Last post Oct 17, 2020 03:39 AM by KathyW
Oct 17, 2020 12:57 AM|vj78|LINK
The server tag is not well formed. This is in masterpage.
<li><a runat="server" href="~/Products?userId='" <%: Session("userid") %> "'" > Products </a></li>
Oct 17, 2020 02:20 AM|KathyW|LINK
<%: is not valid.
Is there any reason you need a runat=server in that link? If you do it would be simpler to use a hyperlink and construct the href in code behind. (Or set the HtmlAnchor HRef in code behind).
But a standard HTML link will work:
<a href="/Products?userId=<%= Session["userid"].ToString() %>" > Products </a>
If you are using VB.net, use () instead of  for Session.
I assume you are checking if Session is null in code behind and setting the value to something valid, since doing this in the .aspx page doesn't check for that.
Oct 17, 2020 03:39 AM|KathyW|LINK
Just adding, if you really want to use an HtmlAnchor and bind the Session value to the HRef in the .aspx page, you can do it, but its more work than simply using a standard link, as I showed above.
First, you need to make sure your page has
Second, you have to find, then databind, the Anchor in code behind. An example below, but the actual FindControl you would need depends on where this link is nested in your page structure.
protected void Page_Load(object sender, EventArgs e)
HtmlAnchor prodlnk = (HtmlAnchor)(Page.Form.FindControl("MainContent").FindControl("ProductLink"));
And the format for the link in the .aspx page would be:
<a runat="server" ID="ProductLink" HRef=<%# "~/Products?userId=" + Session["userid"].ToString() %> >Products</a>
I'm using C#. You'll need to modify your syntax if you are using VB.net.