views:

140

answers:

3

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 sure 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?

A: 

Have you tried including the script using the ClientScriptManager?

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

GoodEnough
+2  A: 

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.

bashmohandes
+1  A: 

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