title: Postback alternative with 2 dependent dropdown list in asp.net
body: <p>I have 2 dependent drop down lists in an aspx web form, the first drop down gets the printer brand name from a database and the second one gets the model based on the brand selected in the first drop down list.</p>
  
  <p>The code linked below is working but it uses postback and it is a problem for me since I'm working with tabs, it keeps getting back to first tab after each postback.</p>
  
  <p>I was wondering if there is an alternative for post back in my case.</p>
  
  <p>Thank you</p>
  
  <pre><code>    &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="&lt;%$ ConnectionStrings:PrintXConnectionString_youssef %&gt;" SelectCommand="SELECT * FROM [Brand]"&gt;&lt;/asp:SqlDataSource&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="&lt;%$ ConnectionStrings:PrintXConnectionString_youssef %&gt;" SelectCommand="SELECT Distinct P.p_model FROM [Printer] AS P JOIN [Brand] AS B ON P.b_code=B.b_code WHERE (B.b_name = @b_name )"&gt;
         &lt;SelectParameters&gt;
             &lt;asp:ControlParameter ControlID="DropDownList1" Name="b_name" PropertyName="SelectedValue" Type="String" /&gt;
         &lt;/SelectParameters&gt;
         &lt;/asp:SqlDataSource&gt;
  
              &lt;label class="control-label col-sm-8"&gt;Printer brand:&lt;/label&gt;
              &lt;asp:DropDownList ID="DropDownList1" AutoPostBack="true" CssClass="form-control" runat="server" DataSourceID="SqlDataSource2" DataTextField="b_name" DataValueField="b_name"&gt;
              &lt;/asp:DropDownList&gt;
  
              &lt;label class="control-label col-sm-8"&gt;Model reference:&lt;/label&gt;
              &lt;asp:DropDownList ID="DropDownList2" runat="server" CssClass="form-control" DataSourceID="SqlDataSource3" DataTextField="p_model" DataValueField="p_model"&gt;
              &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>SOLVED: I added a script manager and an AJAX update panel control from the toolbox in Visual Studio. Here's the code:</p>
  
  <pre><code>     &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;&lt;/asp:ScriptManager&gt;
          &lt;div class="form-group"&gt;
              &lt;label class="control-label col-sm-8"&gt;Printer Brand:&lt;/label&gt;
              &lt;asp:DropDownList ID="DropDownList1" AutoPostBack="true" CssClass="form-control" runat="server" DataSourceID="SqlDataSource2" DataTextField="b_name" DataValueField="b_name"&gt;
              &lt;/asp:DropDownList&gt;
          &lt;/div&gt;
  
          &lt;asp:UpdatePanel ID="printerpanel" runat="server"&gt;
              &lt;ContentTemplate&gt;
                  &lt;div class="form-group"&gt;
                      &lt;label class="control-label col-sm-8"&gt;Model reference:&lt;/label&gt;
                      &lt;asp:DropDownList ID="DropDownList2" runat="server" CssClass="form-control" DataSourceID="SqlDataSource3" DataTextField="p_model" DataValueField="p_model"&gt;
                      &lt;/asp:DropDownList&gt;
                  &lt;/div&gt;
              &lt;/ContentTemplate&gt;
              &lt;Triggers&gt;
                  &lt;asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /&gt;
              &lt;/Triggers&gt;
          &lt;/asp:UpdatePanel&gt;
  </code></pre>