title: How to retrieve ID of button clicked within usercontrol on Asp.net page?
body: <p>I have a page that I am working on that I'm linking multiple user controls to.  The user control contains 3 buttons, an attach, clear and view button.  When a user clicks on any control on the page, the resulting information is "dumped" into the last visible control on the page.</p>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" MasterPageFile="DefaultPage.master" %&gt;
  &lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %&gt;
  &lt;%@ Register tagName="FileHandler" src="FileHandling.ascx" tagPrefix="ucFile" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server"&gt;
  &lt;asp:UpdatePanel ID="upPanel" UpdateMode="Conditional" runat="server"&gt;
  &lt;ContentTemplate&gt;
  &lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;ucFile:FileHandler ID="fFile1" runat="server" /&gt;
  &lt;/td&gt;
  &lt;td&gt;
  &lt;ucFile:FileHandler ID="fFile2" runat="server" /&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>All file handling and processing is handled within the control, with an event when the upload to the file server is complete via a file name that was generated.  When either button is clicked, the file name is always stored internal to the control in the last control's text box.
  Control code:</p>
  
  <pre><code>&lt;table style="width: 50%;"&gt;
      &lt;tr style="white-space: nowrap;"&gt;
          &lt;td style="width: 1%;"&gt;
              &lt;asp:Label runat="server" ID="lblFile" /&gt;
          &lt;/td&gt;
          &lt;td style="width: 20%;"&gt;
             &lt;asp:TextBox ID="txtFile" CssClass="backColor" runat="server" OnTextChanged="FileInformationChanged" /&gt;
          &lt;/td&gt;
          &lt;td style="width: 1%"&gt;
              &lt;%--&lt;asp:Button runat="server" ID="btnUpload" CssClass="btn" Text="Attach"  OnClick="UploadFile"/&gt;--%&gt;
              &lt;input type="button" id="btnUpload" class="btn" tabindex="30" value="Attach" onclick="SetupUpload();" /&gt;
          &lt;/td&gt;
          &lt;td style="width: 1%"&gt;
              &lt;%--&lt;asp:Button runat="server" ID="btnClear" Text="Clear" CssClass="btn" OnClick="ClearTextValue"/&gt;--%&gt;
              &lt;input type="button" id="btnClearFile" class="btn" value="Clear" onclick="document.getElementById('&lt;%=txtFile.ClientID%&gt;').value = '';document.getElementById('&lt;%=hfFile.ClientID%&gt;').value = '';" /&gt;
          &lt;/td&gt;
          &lt;td style="width: 1%"&gt;
              &lt;a href="#here" onclick="ViewLink(document.getElementById('&lt;%=hfFile.ClientID%&gt;').value, '')"&gt;View&lt;/a&gt;
          &lt;/td&gt;
          &lt;td style="width: 1%"&gt;
              &lt;asp:HiddenField ID="hfFile" runat="server" /&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;script type="text/javascript"&gt;
      var ItemPath = "";
      function SetupUpload(File) {
          ItemPath = File;
          VersionAttach('&lt;%=UploadPath%&gt;', 'true');
      }
      function UploadComplete(File) {
          document.getElementById('&lt;%=txtFile.ClientID%&gt;').value =  File.substring(File.lastIndexOf("/") + 1);
          document.getElementById('&lt;%=hfFile.ClientID%&gt;').value = File;
          alert('&lt;%=txtFile.Text %&gt;');
          alert('&lt;%=ClientID %&gt;')
      }
      function ViewLink(File, Alert) {
          if (File != "") {
              if (File.indexOf("../data/") != -1) {
                  window.open(File, '_blank');
              }
              else {
                  window.open('../data/&lt;%=UploadPath%&gt;/' + File, '_blank');
              }
          }
          else if (Alert == "") {
              alert('No file has been uploaded for this field.');
          }
      }
  &lt;/script&gt;
  </code></pre>