Avatar of Kan64
Kan64
 asked on

Asp.net Usercontrol javascript linking

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
ASP.NET

Avatar of undefined
Last Comment
ajitha75

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ajitha75

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23