troubleshooting Question

Asp.net Usercontrol javascript linking

Avatar of Kan64
Kan64 asked on
ASP.NET
1 Comment1 Solution1205 ViewsLast Modified:
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>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <uc1:WebUserControl1 ID="WebUserControl11" runat="server" />
    </form>
</body>
</html>

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()
{
  alert('called');
  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.

Thanks
ASKER CERTIFIED SOLUTION
ajitha75

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros