title: DropDownList not posting back, even with AutoPostBack set
body: <p><strong>Obscure solution at end of post</strong></p>
  
  <p>Using asp.net page with C# codebehind, I have successfully built and populated a DropDownList.</p>
  
  <p>What I would like to do is capture a new value selected from the dropdownlist (preferrably using a postback to my codebehind). The codebehind can then update other things on the page based on this newly selected dropdownlist value.</p>
  
  <p>My first attempt was to use </p>
  
  <pre><code>&lt;asp:DropDownList ID="myDDL" runat="server" AutoPostBack="true" OnSelectedIndexChanged="foo"&gt;&lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>with the C# method</p>
  
  <pre><code>public void foo(object sender, EventArgs e)
  {
      DropDownList ddl = sender as DropDownList;
      string myValue = "";
  
      if (ddl != null)
      {
          myValue = ddl.SelectedValue;
          // Do some stuff
      }
  }
  </code></pre>
  
  <p>This did not work. When the selected index was changed, it simply reloaded the page, but the IsPostBack flag was always false.</p>
  
  <p>So I sifted through SO and tried a number of different tactics. Most recently, I tried to register the client-side onChange event in the codebehind and turned off the AutoPostBack.</p>
  
  <p>in the ASP.Net page:</p>
  
  <pre><code>&lt;asp:DropDownList ID="myDDL" runat="server" AutoPostBack="false"&gt;&lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>in the codebehind: </p>
  
  <pre><code>myDDL.Attributes.Add("onChange", "doSomeStuff(this);"); // Done on databind.
  </code></pre>
  
  <p>I added the client-side javascript to call the page's __doPostBack function </p>
  
  <pre><code>&lt;script language="javascript" type="text/javascript"&gt;
      function doSomeStuff(ddl) {
          var ddlVals = document.getElementById(ddl.id);
  
          __doPostBack(ddlVals, '');
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>This also failed, although I thought it was going somewhere when I saw the javascript execute properly.</p>
  
  <p>Looking in the codebehind, though, it's still not working. When I put a breakpoint in the Page_Load IsPostBack is false! But it's supposed to be a postback!? It was posted back using __doPostBack and (seperately) automatically with AutoPostBack="true"</p>
  
  <p>So I dug deeper. </p>
  
  <p>According to this MSDN article (http://msdn.microsoft.com/en-us/library/ms178141(v=VS.85).aspx) based on the results on the page load I'm doing a "Server Transfer" rather than the desired Postback (IsPostBack is false, PreviousPage is, as expected, the same page that should be posting back, IsCallback is false, and IsCrossPagePosting is false).</p>
  
  <p><strong>What could be going on to hyjack the AutoPostBack</strong> and the __doPostBack to make it look and act like a "Server Transfer"?</p>
  
  <p><strong>What can I set/check on the parent control</strong>/page to make sure it's allowing postbacks?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>The Page_Load looks something like:</p>
  
  <pre><code>private SpecialDataObject _someData;
  private string foobar;
  public void Page_Load(object sender, EventArgs e)
  {
      //set some variables.
      this.foobar = "blah";
  
      LoadSomeUnrelatedData();
  
      if (!IsPostBack)
      {
          if (_someData == null)
          {
              LoadDataWithoutBinding();
          }
          BindMyData();
      }
  }
  </code></pre>
  
  <p>With a breakpoint at <code>//set some variables</code> the Page.IsPostBack is always false even after AutoPostBack.</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>The answer was in the Server Transfer. In a distant control loaded from the master page, the URL is inspected and rerouted before it hits the page, effectively negating my postback. I didn't see it before because I had added the breakpoints only in the target page.</p>