开发者

How to load web page js after master page js script

开发者 https://www.devze.com 2023-03-25 16:54 出处:网络
I have javascript code in a web page that 开发者_StackOverflowneeds to get loaded after js code in the master page, but .NET seems to want things the other way around. I have tried using ClientScript.

I have javascript code in a web page that 开发者_StackOverflowneeds to get loaded after js code in the master page, but .NET seems to want things the other way around. I have tried using ClientScript.RegisterStartupScript, but the web page code still appears in the output stream before the master page script.


Try content placeholders for this.

In the master page:

<head>
...
<script type="text/javascript">
//master's javascript
</script>
<asp:ContentPlaceHolder ID="JsContent" runat="server" />
...
</head>

in the content web page:

<asp:Content ContentPlaceHolderID="JsContent" runat="server">
<script type="text/javascript">
//page's javascript
//this js block will appear after the master's one
</script>
</asp:Content>


RegisterClientScriptBlock , which inserts a script block at the top of the rendered page.

RegisterStartupScript , which inserts a script block at the end of the rendered page.

http://msdn.microsoft.com/en-us/library/3hc29e2a.aspx#IncludingCustomClientScriptinASP.NETPages

0

精彩评论

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