Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should Page.Header.DataBind be called?

I'm trying to resolve correct paths to javascript scripts in my head section using:

<script src="<%# ResolveUrl("~/Scripts/jquery-1.4.2.min.js") %>" type="text/javascript" />

In order to resolve the path I need to call databind using Page.Header.DataBind(); What event should I place the databind call in?

Thanks.

Reference: http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/

When I put it in Page_Load as the article suggests it works (only for firefox), but I wonder if this is the correct place.

When I follow this article IE 8 renders:

<script src="/Scripts/jquery-1.4.2.min.js" type="text/javascript" />

and firefox 3.6 correctly renders:

<script src="../../Scripts/jquery-1.4.2.min.js" type="text/javascript" />

Update:

Fixed browser issues by updating a script reference in a referenced user control to use ResolveUrl. Now browser issues are fixed. Still wondering where to put Databind.

like image 222
O.O Avatar asked Nov 05 '22 08:11

O.O


1 Answers

Change <%# to <%=, at which point you no longer need to call Page.Header.DataBind();, since you are not doing any actual databinding in your expression.

See this question for the differences in the ASP.NET tags.

From the master page I use in all my projects:

<script type="text/javascript" src='<%= ResolveUrl("~/js/jquery-1.4.2.min.js") %>' ></script>
like image 93
Jason Berkan Avatar answered Nov 10 '22 18:11

Jason Berkan