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.
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>
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