Reference to styles and script's in Master.Page using ResolveUrl

0

In Master.Page I make references to the styles and scripts that will be inherited by the other pages through ResolveUrl.

<script src="<%# ResolveUrl("~/") %>Scripts/jquery-1.11.1.js" type='text/javascript'></script>
<script src="<%# ResolveUrl("~/") %>Scripts/jQuery-Mask-Plugin.js" type='text/javascript'></script>
<script src="<%# ResolveUrl("~/") %>Scripts/jQuery-Formatacao.js" type='text/javascript'></script>

<link href="<%# ResolveUrl("~/") %>Styles/estilo.css" rel='stylesheet' type='text/css' />

I saw some posts that suggest inserting the code below so that the initial reference can be effective:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    Page.Header.DataBind();
}

Is this really necessary?

I'm using the 4.0 framework.

    
asked by anonymous 24.11.2014 / 15:35

1 answer

2

The <%# %> tags are used to > data binding , and therefore it is necessary that the code executes the binding ( DataBind() ) if it is not done automatically (as it happens in data binding controls). You can choose to use the <%: %> tags, without the need to use the second block of code that is in your question statement.

In this case, the code would look like this:

<script src="<%: ResolveUrl("~/Scripts/jquery-1.11.1.js") %>" type='text/javascript'></script>
<script src="<%: ResolveUrl("~/Scripts/jQuery-Mask-Plugin.js") %>" type='text/javascript'></script>
<script src="<%: ResolveUrl("~/Scripts/jQuery-Formatacao.js") %>" type='text/javascript'></script>

<link href="<%: ResolveUrl("~/Styles/estilo.css") %>" rel='stylesheet' type='text/css' />

For future questions, here's an explanation of how ASP.NET tags work:

<% %> defines a block of server code that runs during page rendering. You can run declarations and call methods of the page class where the block is inserted ( link ).

<%= %> works as a Response.Write() , more useful for displaying unique information ( ).

<%# %> defines a data-binding expression ( link ).

<%$ %> defines an ASP.NET expressions ( link ).

<%@ %> defines a policy expression ( link ) .

<%-- --%> defines a server-side comment block (

24.11.2014 / 17:28