Search code examples
c#asp.netjqueryasp.net-3.5

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.


Solution

  • Fixed by adding ID and runat="server" to link (stylesheet), finding control in header, calling databind on link instead of entire header.