Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2008-06-20
1
Medium Priority
?
429 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 2000 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
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…
Suggested Courses

609 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