We help IT Professionals succeed at work.

Asp.net Usercontrol javascript linking

Kan64 asked
Last Modified: 2008-07-19
Can I Use external js file for Usercontrol script?

here is the asp.page

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>

    <script src="JScript1.js" type="text/javascript"></script>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />

Here is the usercontrol page

<script type ="text/javascript"></script>
<asp:Label ID="Name1" runat="server" Text="Label" /><asp:TextBox ID="TextBox1" runat="server" /><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return ShowName();" />

and here is javascript code
function ShowName()
  var obj = $get('<%= this.TextBox1.ClientID %>');
  alert ( obj.value);
  return false;

I getting error on the   var obj = $get('<%= this.TextBox1.ClientID %>'); line.

If I put the script on the user control page then it works but I want to all my script in one js file and link it on the .aspx page using the controls.

Watch Question

This one is on us!
(Get your first solution completely free - no credit card required)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.