title: Saving drop down list value and set selected index after postback
body: <p>I have a small page with 3 drop down list and text box.
  my goal is to select a value in every one of the drop down boxes (or any combination) and after post back to set the selected value with the value from last search.
  one of the problems  is that 1. after every select in IE the page is doing post back(obviously)
  and even when a added the attribute for enable view state the drop down list does not retain the selected value.</p>
  
  <pre><code> &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="QSerch.aspx.cs" Inherits="QSerch"
      EnableViewState="true" EnableEventValidation="true" EnableViewStateMac="true"%&gt;
  
  &lt;%@ Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      Namespace="System.Web.UI" TagPrefix="asp" %&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;style type="text/css"&gt;
          .ddlstl
          {
              font-size: 13px;
              font-family: Arial;
          }
          #Iframe1
          {
              height: 700px;
              width: 540px;
          }
          .style2
          {
              width: 243px;
          }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body dir="rtl"&gt;
      &lt;form id="form1" runat="server" enableviewstate="true"&gt;
      &lt;asp:ScriptManager ID="ScriptManager1" runat="server" EnableScriptGlobalization="True"
          EnablePartialRendering="true" LoadScriptsBeforeUI="false" ScriptMode="Release"&gt;
      &lt;/asp:ScriptManager&gt;
      &lt;div style="float: right; width: 28px;"&gt;
          &amp;nbsp;&lt;/div&gt;
      &lt;div style="text-align: right; float: right;"&gt;
          &lt;table border="0" cellpadding="0" cellspacing="0"&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;table border="0"&gt;
                          &lt;tr&gt;
                              &lt;td style="width: 170px;"&gt;
                                  &lt;asp:DropDownList ID="ddlMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                      Height="22px" Width="160px" EnableViewState="true" OnSelectedIndexChanged="ddlMec_SelectedIndexChanged"&gt;
                                  &lt;/asp:DropDownList&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td style="width: 20px;"&gt;
                                  &lt;asp:DropDownList ID="ddlTMec" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                      Height="22px" Width="160px" OnSelectedIndexChanged="ddlTMec_SelectedIndexChanged"
                                      EnableViewState="true"&gt;
                                      &lt;asp:ListItem Value="-1"&gt;בחר תפקיד&lt;/asp:ListItem&gt;
                                  &lt;/asp:DropDownList&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td style="width: 170px;"&gt;
                                  &lt;asp:DropDownList ID="ddlArea" runat="server" AutoPostBack="True" CssClass="ddlstl"
                                      DataSourceID="adsArea" DataTextField="name_area" DataValueField="id_area" Height="22px"
                                      Width="160px" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged" AppendDataBoundItems="true"
                                      EnableViewState="true"&gt;
                                      &lt;asp:ListItem Value="-1" Text="בחר איזור"&gt;&lt;/asp:ListItem&gt;
                                  &lt;/asp:DropDownList&gt;
                                  &lt;asp:AccessDataSource ID="adsArea" runat="server" DataFile="~/App_Data/Adam.mdb"
                                      SelectCommand="SELECT [id_area], [name_area] FROM [table_area] ORDER BY [name_area]"&gt;
                                  &lt;/asp:AccessDataSource&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;
                                  &lt;asp:TextBox runat="server" Text="חיפוש חופשי" ID="txtFreeText" Style="font-size: 12px;
                                      height: 15px; width: 151px" /&gt;
                                  &lt;%--&lt;input type="text" value="חיפוש חופשי" onfocus="deleteFreeText()" id="FreeText" name="FreeText"
                                              style="font-size: 12px; height: 15px; width: 151px" runat="server" /&gt;--%&gt;
                                  &lt;br /&gt;
                              &lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td align="right"&gt;
                      &lt;asp:UpdatePanel ID="UpdatePanel2" runat="server" RenderMode="Inline" UpdateMode="Conditional"&gt;
                          &lt;ContentTemplate&gt;
                              &lt;iframe id="Iframe1" runat="server" frameborder="0" name="Iframe1" scrolling="no"
                                  width="360px" src="" style="overflow: auto"&gt;&lt;/iframe&gt;
                          &lt;/ContentTemplate&gt;
                      &lt;/asp:UpdatePanel&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          &lt;/table&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
      protected void Page_Load(object sender, EventArgs e)
      {
          TextBox tb = (TextBox)FindControl("txtFreeText");
          tb.Attributes.Add("onfocus", "this.value = ''");
          if (!Page.IsPostBack)
          {
              LoadProffesion();
          }
      }
  </code></pre>