Javascript inside an ASCX

  • Thread starter Thread starter eaguilar
  • Start date Start date
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,
 
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.
 
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>
 
Maybe your linked files hadn't yet loaded when the call to the contained
function was made?

Tim
 
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.
 
Back
Top