Solved

Calling a JavaScript file from a C# .aspx file (special case)

Posted on 2008-06-20
1
399 Views
Last Modified: 2013-12-16
Hi,

I'm building this website in which I have a C# .aspx page that doesn't allow for the <head>, <html> or <body> tags, otherwise I get the error:
"Only content controls are allowed directly in a content page that contains Content controls."

The same goes the this file master page.

I need to invoke from the .aspx file a JavaScript file:
<head>
<script><src="functions.js" type="text/javascript">
<head>

but I can't do it because, as I said, the page doesn't allow the <head> tag.

Putting the JavaScript code is not an option, because - I can't imagine why - it works in Firefox, but not in Internet Explorer.

So, my question to you, is how do I invoke the JavaScript file from the .aspx one under these conditions ?

Any help would be appreciated.

Warm Regards,
Mário Gamito
0
Comment
Question by:angelsofgrace2006
1 Comment
 
LVL 19

Accepted Solution

by:
Albert Van Halen earned 500 total points
ID: 21830555
Use Page.ClientScript.RegisterScriptInclude in your codebehind.
// check if it's already registered
if(!Page.ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "MyFunctions"))
	Page.ClientScript.RegisterScriptInclude(this.GetType(), "MyFunctions", "functions.js");

Open in new window

0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question