title: Javascript functions inside ASP.NET User Control
body: <p>I created ASP.NET user control with javascript function :</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="TestControl.ascx.cs" Inherits="BingTranslator.Web.WebUserControl1" %&gt;
  &lt;script type="text/javascript"&gt;
      function example() {
          alert('&lt;%=ExampleButton.ClientID%&gt;');
          return false;
      }
  &lt;/script&gt;
  &lt;asp:Button ID="ExampleButton" runat="server" Text="Example"/&gt;
  </code></pre>
  
  <p>I want to call "example" function when user move mouse to button, so I added attribute for button:</p>
  
  <pre><code>ExampleButton.Attributes.Add("onmouseover", "example()");
  </code></pre>
  
  <p>It works well, but when I need two controls on same page I got a problems. ASP.NET generates code with two functions with same name, what is wrong:  </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      function example() {
          alert('TestControl1_ExampleButton');
          return false;
      }
  &lt;/script&gt;
  &lt;input type="submit" name="TestControl1$ExampleButton" value="Example" id="TestControl1_ExampleButton" onmouseover="example()" /&gt;
  
  
  &lt;script type="text/javascript"&gt;
      function example() {
          alert('TestControl2_ExampleButton');
          return false;
      }
  &lt;/script&gt;
  &lt;input type="submit" name="TestControl2$ExampleButton" value="Example" id="TestControl2_ExampleButton" onmouseover="example()" /&gt;
  </code></pre>
  
  <p>And always onmouseover event on any button will call second function. I am able resolve this issue by adding java script code with client Id directly to attriburte onmouseover.</p>
  
  <pre><code>ExampleButton.Attributes.Add("onmouseover", "[Here will be javascript code]");
  </code></pre>
  
  <p>But it is not very harmonious solution as for me. Please advise, how I can better resolve such issue. </p>
  
  <p>P.S. There will be much more Javascript code, I added two string upper just for example.</p>