RegisterClientScriptInclude in masterpage

Hi,

I’m trying to include and use a javascript file in my masterpage… niftycube actually. Anyways, trying to add this javascript and call the function is proving to be quite difficult. I’ve looked over most of the solutions on this forum already, but none seem to work for me. Here’s what I have so far on the Page_Load.

String csname = "niftycube";
ClientScriptManager cs = Page.ClientScript;
String csurl = "niftycube.js";
Type cstype = this.GetType();

// Check to see if the include script exists already.
if (!cs.IsClientScriptIncludeRegistered(cstype, csname))
{
     cs.RegisterClientScriptInclude(cstype, csname, ResolveUrl(csurl));
}

So I’ve actually tried a variety of different ways to get the javascript file properly included. I’ve used different values for ‘csurl’ include “~/niftycube.js”, “niftcube.js”, “~/scripts/niftycube.js” (after moving it there of course), and so on. No matter what I do, I’m getting a Javascript error saying “Syntax error, Line 4, Char 1”.

When I look at the source code actually generated, it actually APPEARS to be correct! But I’m still getting the syntax error warning. As soon as I removed the “RegisterClientScriptInclude” line of code, the syntax error warning goes away, not to mention the calls to the javascript functions by adding RegisterClientScriptBlock are also failing.

<script src="/CentralProject/niftycube.js" type="text/javascript"></script>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s