Solved

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

Posted on 2008-06-20
1
373 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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now