title: delete a submit button from ASP.NET form
body: <p>I have tried a <code>...Controls.Remove(ButtonToRemove)</code> from a bunch of containers including the <code>Page</code>, <code>NamingContainer</code>, and <code>Content</code> content placeholder control.  I have also tried setting the button Visible property to false, disabling the Button control, and setting the Text to an empty string.</p>
  
  <p>Having tried all of those things and seeing the debugger run over the above described attempt code lines, and still seeing the button in question on the page when it shouldn't be, I am wondering if there is a browser rule that a submit button has to be visible no matter what.  I suspect that especially because a bunch of similarly deleted TextBox and Label controls are being correctly removed using the above methods.</p>
  
  <p>This is the method I call from the Page_Load code the objects are defined as normal:</p>
  
  <pre><code>public void RemoveInputControls()
  {
      LabelD.Text = string.Empty;
      LabelF.Text = string.Empty;
      LabelS.Text = string.Empty;
      TextBoxK.Visible = false;
      TextBoxK.ReadOnly = true;
      TextBoxK.Page.Controls.Remove(TextBoxK);
      TextBoxK.NamingContainer.Controls.Remove(TextBoxK);
      TextBoxK.Enabled = false;
      Content2.Controls.Remove(Content2.FindControl(TextBoxK.ID));
      Page.Controls.Remove(TextBoxK);
  
      ButtonSubmit.UseSubmitBehavior = false;
      ButtonSubmit.Text = string.Empty;
      ButtonSubmit.Visible = false;
      ButtonSubmit.Page.Controls.Remove(ButtonSubmit);
      ButtonSubmit.NamingContainer.Controls.Remove(ButtonSubmit);
      ButtonSubmit.Enabled = false;
      Content2.Controls.Remove(Content2.FindControl(ButtonSubmit.ID));
      Page.Controls.Remove(ButtonSubmit);
  }
  </code></pre>
  
  <p>(sorry, I don't know how better to format asp.net markup for stackoverflow) and here is the page code, you can see it is a sub-page of a master page:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="Index" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"&gt;
      &lt;div class="normal"&gt;
          &lt;br /&gt;
          &lt;h2&gt;&lt;asp:Label ID="LabelD" runat="server" Text="Greetings!" CssClass="cssclass"&gt;&lt;/asp:Label&gt;h2&gt;
          &lt;h4 class="cssh4"&gt;&lt;asp:Label ID="LabelF" runat="server" Text="enter input:"&gt;&lt;/asp:Label&gt;&lt;/h4&gt;
          &lt;asp:TextBox ID="TextBoxK" runat="server" Width="200px"&gt;&lt;/asp:TextBox&gt;
          &lt;h4 class="cssh4"&gt;&lt;asp:Label ID="LabelS" runat="server" Text="click:"&gt;&lt;/asp:Label&gt;&lt;/h4&gt;
          &lt;asp:Button ID="ButtonSubmit" runat="server" Text="Submit Input" Visible="true"/&gt;
      &lt;/div&gt;
  &lt;/asp:Content&gt;
  </code></pre>