title: Type '_Default' already contains a definition
body: <p>I am developing a C# VS 2008 / SQL Server 2008 website.  I have a Gridview. I included the Default.aspx and aspx.cs files below. But when I build this I get the below error:</p>
  
  <blockquote>
    <p>The Type '_Default' already contains a
    definition for 'btnOWrite'</p>
  </blockquote>
  
  <p>What do I need to do to fix this? I am not getting any errors now; just that this grid does not show up. Thanks!</p>
  
  <p>ASPX file:</p>
  
  <pre><code>&lt;%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server"&gt;
      &lt;asp:Panel runat="server" ID="AuthenticatedMessagePanel"&gt;
          &lt;asp:Label runat="server" ID="WelcomeBackMessage"&gt;&lt;/asp:Label&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;asp:Label ID="tableLabel" runat="server" Font-Bold="True" Text="Select target table:"&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;asp:Label ID="inputLabel" runat="server" Font-Bold="True" Text="Select input file:"&gt;&lt;/asp:Label&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td valign="top"&gt;
                      &lt;asp:Label ID="feedbackLabel" runat="server"&gt;&lt;/asp:Label&gt;
                      &lt;asp:SqlDataSource ID="SelectTables" runat="server" ConnectionString="&lt;%$ ConnectionStrings:AdventureWorks3_SelectTables %&gt;"
                          SelectCommand="getTableNames" SelectCommandType="StoredProcedure"&gt;
                          &lt;SelectParameters&gt;
                              &lt;asp:QueryStringParameter DefaultValue="Person" Name="SchemaName" QueryStringField="SchemaName"
                                  Type="String" /&gt;
                          &lt;/SelectParameters&gt;
                      &lt;/asp:SqlDataSource&gt;
                      &lt;asp:GridView ID="GridView1" DataSourceID="SelectTables" runat="server" Style="width: 400px;"
                          CellPadding="4" ForeColor="#333333" GridLines="None" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                          AutoGenerateSelectButton="True" DataKeyNames="TABLE_NAME"&gt;
                          &lt;RowStyle BackColor="#F7F6F3" ForeColor="#333333" /&gt;
                          &lt;Columns&gt;
                              &lt;asp:BoundField HeaderText="TABLE_NAME" DataField="TABLE_NAME" /&gt;
                          &lt;/Columns&gt;
                          &lt;FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                          &lt;PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /&gt;
                          &lt;SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /&gt;
                          &lt;HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /&gt;
                          &lt;EditRowStyle BackColor="#999999" /&gt;
                          &lt;AlternatingRowStyle BackColor="White" ForeColor="#284775" /&gt;
                      &lt;/asp:GridView&gt;
                  &lt;/td&gt;
                  &lt;td valign="top"&gt;
                      &lt;input id="uploadFile" type="file" size="26" runat="server" name="uploadFile" title="UploadFile" class="greybar" enableviewstate="True" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
  
          &lt;table&gt;
  &lt;tr&gt;
  &lt;td style="width:150px; height:50px"&gt;&lt;/td&gt;
  &lt;td valign="bottom" style="width:150px; height:50px"&gt;
       &lt;input id="btnOWrite" type="submit" value="Overwrite Data" runat="server" class="greybar"
                        onserverclick="btnOWrite_Click" name="btnOWrite" /&gt;&amp;nbsp;
                        &lt;/td&gt;
  &lt;td style="width:100px"&gt;&lt;/td&gt;
  
  &lt;td valign="bottom" style="width:150px; height:50px"&gt;
      &lt;input id="btnAppend" type="submit" value="Append Data" runat="server" class="greybar" onserverclick="btnAppend_Click" name="btnAppend" /&gt; 
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
      &lt;/asp:Panel&gt;
      &lt;asp:Panel runat="Server" ID="AnonymousMessagePanel"&gt;
          &lt;asp:HyperLink runat="server" ID="lnkLogin" Text="Log In" NavigateUrl="~/Login.aspx"&gt;
          &lt;/asp:HyperLink&gt;
      &lt;/asp:Panel&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>ASPX.CS file:</p>
  
  <pre><code>public partial class _Default : System.Web.UI.Page
  
  //namespace AddFileToSQL
  {
          //protected System.Web.UI.HtmlControls.HtmlInputFile uploadFile;
          protected System.Web.UI.HtmlControls.HtmlInputButton btnOWrite;
          protected System.Web.UI.HtmlControls.HtmlInputButton btnAppend;
          protected System.Web.UI.WebControls.Label Label1;
          protected static string inputfile = "";
          public static string targettable;
          public static string selection;
  
          // Number of controls added to view state
          protected int default_NumberOfControls
          {
              get
              {
                  if (ViewState["default_NumberOfControls"] != null)
                  {
                      return (int)ViewState["default_NumberOfControls"];
                  }
                  else
                  {
                      return 0;
                  }
              }
              set
              {
                  ViewState["default_NumberOfControls"] = value;
              }
          }
  
          protected void uploadFile_onclick(object sender, EventArgs e)
          {
          }
  
          protected void Load_GridData()
          {
              //GridView1.DataSource = ADONET_methods.DisplaySchemaTables();
              //GridView1.DataBind();
          }
  
          protected void btnOWrite_Click(object sender, EventArgs e)
          {
              if (uploadFile.PostedFile.ContentLength &gt; 0)
              {
                  feedbackLabel.Text = "You do not have sufficient access to overwrite table records.";
              }
              else
              {
                  feedbackLabel.Text = "This file does not contain any data.";
              }
          }
  
          protected void btnAppend_Click(object sender, EventArgs e)
          {
              string fullpath = Page.Request.PhysicalApplicationPath;
  
              string path = uploadFile.PostedFile.FileName;
  
              if (File.Exists(path))
              {
                  // Create a file to write to.
                  try
                  {
                      StreamReader sr = new StreamReader(path);
                      string s = "";
                      while (sr.Peek() &gt; 0)
                          s = sr.ReadLine();
                      sr.Close();
                  }
                  catch (IOException exc)
                  {
                      Console.WriteLine(exc.Message + "Cannot open file.");
                      return;
                  }
              }
  
              if (uploadFile.PostedFile.ContentLength &gt; 0)
              {
  
                  inputfile = System.IO.File.ReadAllText(path);
                  Session["Message"] = inputfile;
                  Response.Redirect("DataMatch.aspx");
              }
              else
              {
                  feedbackLabel.Text = "This file does not contain any data.";
              }
          }
  
          protected void Page_Load(object sender, EventArgs e)
          {
              if (Request.IsAuthenticated)
              {
                  WelcomeBackMessage.Text = "Welcome back, " + User.Identity.Name + "!";
  
                  // Reference the CustomPrincipal / CustomIdentity
                  CustomIdentity ident = User.Identity as CustomIdentity;
                  if (ident != null)
                      WelcomeBackMessage.Text += string.Format(" You are the {0} of {1}.", ident.Title, ident.CompanyName);
  
                  AuthenticatedMessagePanel.Visible = true;
                  AnonymousMessagePanel.Visible = false;
                  if (!Page.IsPostBack)
                  {
                      Load_GridData();
                  }                                
              }
              else
              {
                  AuthenticatedMessagePanel.Visible = false;
                  AnonymousMessagePanel.Visible = true;
              }
          }
  
          protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
          {
              GridViewRow row = GridView1.SelectedRow;
              targettable = row.Cells[2].Text;
          }
      }
  </code></pre>