开发者

When should Page.Header.DataBind be called?

开发者 https://www.devze.com 2023-01-18 23:32 出处:网络
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\" />

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.

Refere开发者_如何学运维nce: 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>


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


I managed to fix this issue for myself by calling Page.DataBind() on Page_Load.

Update: Just calling it on Page_Load in the master page caused some bugs with gridview commands not working. Putting it inside a !Page.IsPostBack check fixes it.

0

精彩评论

暂无评论...
验证码 换一张
取 消