title: How to center div element in ASP.NET?
body: <p>I've got the following code:</p>
  
  <pre><code>   &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %&gt;
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="Styles/TomsStyleSheet.css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
      &lt;div class="centerBlock"&gt;
          &lt;asp:GridView ID="GridView1" runat="server" CcsClass="center"&gt;
          &lt;/asp:GridView&gt;
      &lt;/div&gt;
      &lt;br /&gt;
      &lt;div class="centerBlock"&gt;
          &lt;asp:Label ID="Label1" runat="server" Text="Enter Directory Path: "&gt;&lt;/asp:Label&gt;
          &lt;asp:TextBox ID="TextBox" Width="200px" runat="server"&gt;&lt;/asp:TextBox&gt;
          &lt;br /&gt;
          &lt;br /&gt;
          &lt;asp:Button ID="checksumBtn" runat="server" Text="Calculate Checksum" OnClick="CalculateChecksum" /&gt;
          &lt;br /&gt;
          &lt;asp:Label ID="errorMsg" runat="server" Text="" CssClass="error"&gt;&lt;/asp:Label&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Here's the css:</p>
  
  <pre><code>.centerBlock
  {
      margin-left:auto;
      margin-right:auto;
      width:50%;
  }
  </code></pre>
  
  <p>What I'm trying to do is simply center it... horizontally for now but vertically would also be good so it's smack dab in the middle of the page.</p>
  
  <p>I know that it's not a problem of referencing the external style sheet because CssClass="error" on the last line works fine. I've also tried <code>&lt;div style="margin-left:auto;margin-right:auto;"&gt;</code> as according to <a href="https://stackoverflow.com/questions/3616112/how-to-center-one-div-in-form">this suggestion</a> but nothing seems to work. The output is currently left-justified, not centered. I'm using IE 7.</p>