using linked .js file in UserControl

  • Thread starter Thread starter neverstill
  • Start date Start date
N

neverstill

hi-

Has anyone found a way to use a linked .js file in a UserControl? I have a
control that has this line:
<script src="NSClientListBuilder.js"></script>

in that file is a function all test() test has a simple alert() call

I have a button on my usercontrol that will execute test(). Whenn the
script is in the ascx file, it works fine, when it's in a linked .js file I
get a script error. Has anyone and idea why this may be?

of course I have checked paths
filenames
etc

Thanks,
Steve
 
I use scripts to enhance user controls regularly. When you say that you are
generating a script error, do you mean that the script is actually running?
If so, the issue could be with the fact that the user control will decorate
the names of the controls, so if you are trying to put in the ID of the
control only, ASP.NET will add on the name of the user control (which it
does to avoid name collisions - enabling you to have a textbox called "name"
on two different user controls, and still use both controls in a form), and
your script (if running) may simply no longer be able to find the objects
you are looking for. If you view source, you can see the actual names that
the runtime emits, or you could output the UniqueID property of the control
into a global variable (in a client side script block) to enable it to be
accessed.
 
Back
Top