user1477388
user1477388

Reputation: 21420

Setting a Dynamic Href in Hyperlink in MasterPage

The following will work:

<%  if (Sql.ToBoolean(HttpContext.Current.Application["CONFIG.SHOW_REPORTING_LINK"])) 
    { 
%>
    <asp:HyperLink ID="hypReporting" ForeColor="white" Text='Reporting' NavigateUrl="#" CssClass="myAreaLink" Runat="server" />
           &nbsp;<font color="white">|</font>&nbsp; 
<% 
    } 
%>

However, I need a dynamic link, instead of a static one. I tried this:

<%  if (Sql.ToBoolean(HttpContext.Current.Application["CONFIG.SHOW_REPORTING_LINK"])) 
    { 
%>
    <asp:HyperLink ID="hypReporting" ForeColor="white" Text='Reporting' NavigateUrl="<%# Eval(HttpContext.Current.Application["CONFIG.REPORTING_URL"]) %>" CssClass="myAreaLink" Runat="server" />
           &nbsp;<font color="white">|</font>&nbsp; 
<% 
    } 
%>

But, it gives me an error that says, "The server tag is not well formed."

I would normally do this from codebehind, but there is no codebehind in a .master file, right?

Thanks for your help.

Upvotes: 0

Views: 1096

Answers (1)

MikeSmithDev
MikeSmithDev

Reputation: 15797

It's the double quotes in the NavigateUrl that are causing the bad server tag. It should be:

NavigateUrl='<%# Eval(HttpContext.Current.Application["CONFIG.REPORTING_URL"]) %>'

And you should get rid of that <font> tag and just use CSS. That tag is deprecated.

Yes there is code-behind in the master page file (right-click -> view code; or in the Solution Explorer, ensure that "Show All Files" is clicked). It would likely be easier/cleaner to do it there.

Upvotes: 3

Related Questions