Solved

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

Posted on 2008-06-20
1
416 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

726 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