title: find control on page using vb.net
body: <p>I'm using the FindControl function to look for a control on the page.  It seems super simple and straight forward on MSDN but I can't get it to find the control.  The page I'm using has a MasterPageFile that prepends more to the id that I give the contorl in the aspx file. A simple example that isn't working:</p>
  
  <p>aspx page</p>
  
  <pre><code>&lt;%@ Page Title="Inventory Control Test" Language="VB" AutoEventWireup="false"     MasterPageFile="~/Site.master" CodeFile="Default2.aspx.vb"     Inherits="Sales_ajaxTest_Default2" %&gt;
  
  &lt;asp:Content ID="conHead" ContentPlaceHolderID="head" Runat="Server"&gt;
  
  
  &lt;/asp:Content&gt;
  
  &lt;asp:Content ID="conBody" ContentPlaceHolderID="MainBody" Runat="Server"&gt;
  
     &lt;asp:Button ID="saveAllBtn"  runat="server" Text="Save All" /&gt; 
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>code behind</p>
  
  <pre><code>Partial Class Sales_ajaxTest_Default2
  Inherits System.Web.UI.Page
  
  
  Protected Sub saveAllBtn_Click(sender As Object, e As System.EventArgs) Handles saveAllBtn.Click
      Dim myControl1 As Control = FindControl("ctl00_MainBody_saveAllBtn")
      If (Not myControl1 Is Nothing) Then
  
          MsgBox("Control ID is : " &amp; myControl1.ID)
      Else
          'Response.Write("Control not found.....")
          MsgBox("Control not found.....")
      End If
  End Sub
  </code></pre>
  
  <p>End Class</p>
  
  <p>I get that msgbox isn't a web thing I'm just using it for this example.
  If i use "saveAllBtn", which is the id given to the control, in the FindControl I get "control not found".  If I try this, on a stand alone page without a masterpage it works fine.</p>
  
  <p>If I inspect the element using chrome I find that the ID of the button has been changed to "ctl00_MainBody_saveAllBtn" but if I use that in the FindControl I still get "control not found"</p>