开发者

Content Specific JavaScript and Master Pages

开发者 https://www.devze.com 2022-12-09 03:22 出处:网络
I have some boiler-plate script required for a Telerik RadGrid on one of my content pages.ASP.NET complains if I try and place the script inside the content element, and it complains if I place the sc

I have some boiler-plate script required for a Telerik RadGrid on one of my content pages. ASP.NET complains if I try and place the script inside the content element, and it complains if I place the script in the master page, because the grid referenced by the script doesn't yet exist 'in' the master page.

I'm s开发者_开发知识库ure there is something fairly simple, or maybe simpler with Telerik, but I just don't have a clue how to handle this. Can somebody please give me some tips?


You can use the ScriptManager control in your master page, and within every content page or even user control if you needed to add a page specific javascript you can use the ScriptManagerProxy control which will append to the original list of scripts mentioned in the ScriptManager control in the master page.


I'm not sure if this is what you want, but here is what I would do.

On master Page:

    <%@ Master Language="c#" %>
<head>
    <script type="text/javascript>
    function somefuntion(){
    //your code here
    }
    </script>
</head>
...

On Content Page:

<%@ Page Language="c#" MasterFile="~/Web.Master" %>
<script runat=server>
protected void Page_Load (object sender, eventargs e)
{
ScriptManager.RegisterStartupScript(Page, Page.GetType(), Guid.NewGuid().ToString(), "somefunction()", true)
}
</script>


Have you tried including the script using the ClientScriptManager?

Use the manager's RegisterClientScriptInclude method in your Page_PreRender event.

0

精彩评论

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