Javascript inside an ASCX

E

eaguilar

Hi,

I am having problems trying to have code in a .js file work inside an ASCX
control. The control and the app build ok, but at runtime IE states that the
function I'm calling (which sits inside the .js file) is "undefined".

Any ideas or pointers to the right way of working with javascript inside an
ASCX?

The ascx looks like:

<head>
....
<script type="text/javascript" src="math.js"></script>
<script type="text/javascript" src="requestManagement.js"></script>
....
<script type="text/javascript">
math.init({
</script>
....
</head>



Many thanks in advance,
 
I

Ignacio Machin ( .NET/ C# MVP )

Hi,

I am having problems trying to have code in a .js file work inside an ASCX
control. The control and the app build ok, but at runtime IE states that the
function I'm calling (which sits inside the .js file) is "undefined".

Any ideas or pointers to the right way of working with javascript inside an
ASCX?

The ascx looks like:

<head>
...
  <script type="text/javascript" src="math.js"></script>
  <script type="text/javascript" src="requestManagement.js"></script>
...
  <script type="text/javascript">
        math.init({
  </script>
...
</head>

Many thanks in advance,

Hi,

there is a math class in javascript and apparently you have a naming
confusion.

Also the way you are inserting your scripts is not the best, what if
you put two controls in the same page? you will include twice each
script.
Take a look at the IScriptControl interface in the framework, I would
also check msdn magazine for some article of how to use it.
 
E

eaguilar

Yep, the math thing was just a sample name to illustrate the problem I am
having.

Good point about the interfacing, I will look into that.

Any ideas about why I cannot access the methods on the js from the ascx
itself? I can access them from a aspx or a html without a problem, but I
cannot make the aspx work.

Thanks for your response.

</edwin>
 
T

Tim Williams

Maybe your linked files hadn't yet loaded when the call to the contained
function was made?

Tim
 
I

Ignacio Machin ( .NET/ C# MVP )

Yep, the math thing was just a sample name to illustrate the problem I am
having.

Good point about the interfacing, I will look into that.

Any ideas about why I cannot access the methods on the js from the ascx
itself? I can access them from a aspx or a html without a problem, but I
cannot make the aspx work.

Thanks for your response.

You should without any problem.
The simpler test is including this in your ascx:
<script>
alert(1);
</script>

if that runs, then your javascript is available and working.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top