title: How to Response Redirect to a panel or control in tab container
body: <p>I am working on a tabbed page (4 tabs - tab container) where 2 of them use the same control and have a different gridview with different dats sources which can edit and add items.</p>
  
  <p>Editing and adding items works fine, however when I add an item the gridview or page needs to refresh to display the new item. Using Response.Redirect only refreshes the page and redirects to the first tab. I am working on tabs 2 and 3 and the redirect needs to point to the relevant tab, not always the 1st tab.</p>
  
  <p>Any suggestion on how to do this?</p>
  
  <p>I am using Visual Studio 2010, C# ASP.Net</p>
  
  <p>CODE:</p>
  
  <p>PAGE: </p>
  
  <pre><code>&lt;asp:Content ID="Content2" ContentPlaceHolderID="pnlMainContent" runat="server"&gt;
  &lt;div style="padding: 10px"&gt;
      &lt;cc1:TabContainer ID="tbMain" runat="server" ActiveTabIndex="0" Width="100%" AutoPostBack="true"
          OnActiveTabChanged="tbMain_ActiveTabChanged"&gt;
          &lt;cc1:TabPanel runat="server" ID="tbpgWFTypes" HeaderText="Work Flow Types"&gt;
              &lt;ContentTemplate&gt;
                  &lt;table style="width: 100%"&gt;
                      &lt;tr&gt;
                          &lt;td align="center"&gt;
                               &lt;uc1:ctrlWorkflowTypeControl ID="ctrlWorkflowTypeControl" runat="server" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/ContentTemplate&gt;
          &lt;/cc1:TabPanel&gt;
          &lt;cc1:TabPanel runat="server" ID="tbpgWFStatus" HeaderText="Work Flow Status"&gt;
              &lt;ContentTemplate&gt;
                  &lt;table style="width: 100%"&gt;
                      &lt;tr&gt;
                          &lt;td align="center"&gt;
                              &lt;uc2:ctrlStatusControl ID="ctrlStatusControl" runat="server" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/ContentTemplate&gt;
          &lt;/cc1:TabPanel&gt;
          &lt;cc1:TabPanel runat="server" ID="tbpgWFActions" HeaderText="Work Flow Actions"&gt;
              &lt;ContentTemplate&gt;
                  &lt;table style="width: 100%"&gt;
                      &lt;tr&gt;
                          &lt;td align="center"&gt;
                              &lt;uc3:ctrlActionControl ID="ctrlActionControl" runat="server" /&gt;                                
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/ContentTemplate&gt;
          &lt;/cc1:TabPanel&gt;
          &lt;cc1:TabPanel runat="server" ID="tbpgWFRouting" HeaderText="Work Flow Routing"&gt;
              &lt;ContentTemplate&gt;
                  &lt;table style="width: 100%"&gt;
                      &lt;tr&gt;
                          &lt;td align="center"&gt;
                             &lt;uc4:ctrlWorkflowRoutingControl ID="ctrlWorkflowRoutingControl" runat="server" /&gt;
                          &lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/ContentTemplate&gt;
          &lt;/cc1:TabPanel&gt;
      &lt;/cc1:TabContainer&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>CODE BEHIND:</p>
  
  <pre><code> protected void Page_Load(object sender, EventArgs e)
      {
          tbpgWFTypes.Focus();
          if (!IsPostBack)
          {
              tbMain_ActiveTabChanged(tbMain, null);                                       
          }           
  }
  
  protected void tbMain_ActiveTabChanged(object sender, EventArgs e)
  {
      try
      {
          if (tbMain.ActiveTabIndex == 1)
          {
              ctrlActionControl.ActionPanelMode = true;
              ctrlStatusControl.StatusPanelMode = false;
          }
  
          if (tbMain.ActiveTabIndex == 2)
          {
              ctrlStatusControl.StatusPanelMode = true;
              ctrlActionControl.ActionPanelMode = false;
          }                
      }
      catch (Exception ex)
      {
          Support.ExceptionHandler.HandleException(ex);
      }
    }
  }
  </code></pre>
  
  <p>CONTROL:</p>
  
  <pre><code>    &lt;table&gt;
      &lt;tr&gt;
          &lt;td align="left" colspan="2"&gt;
              &lt;asp:DropDownList ID="ddlWFStatus" runat="server" Width="400px" DataSourceID="dsStatus" DataTextField="Description" Visible="false"&gt;&lt;/asp:DropDownList&gt;
              &lt;asp:DropDownList ID="ddlWFAction" runat="server" Width="400px" DataSourceID="dsAction" DataTextField="Description" Visible="false"&gt;&lt;/asp:DropDownList&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td  colspan="2"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td align="left"  colspan="2"&gt;
          &lt;asp:Panel ID="pnlStatus" runat="server" Visible="false"&gt;
              &lt;asp:GridView ID="gvStatus" runat="server" DataSourceID="dsStatus"
                  AutoGenerateColumns="False" CellPadding="4" DataKeyNames="WFStatusID"
               ForeColor="#333333" EnableSortingAndPagingCallbacks="True" AllowPaging="True" 
                  AllowSorting="True" onselectedindexchanged="gvStatus_SelectedIndexChanged"&gt;
                 &lt;Columns&gt;
                  &lt;asp:BoundField DataField="WFStatusID" HeaderText="WFStatusID" SortExpression="WFStatusID" Visible="false"&gt;
                      &lt;ItemStyle HorizontalAlign="Left" Width="400px" /&gt; 
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description"&gt;
                      &lt;ItemStyle HorizontalAlign="Left" Width="400px" /&gt; 
                  &lt;/asp:BoundField&gt;
                 &lt;asp:CommandField  ButtonType="Button" EditText="Edit" ShowEditButton="true" /&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;/asp:Panel&gt;
               &lt;asp:Panel ID="pnlAction" runat="server" Visible="false"&gt;
              &lt;asp:GridView ID="gvAction" runat="server" DataSourceID="dsAction"
                  AutoGenerateColumns="False" CellPadding="4" DataKeyNames="WFActionID"
               ForeColor="#333333" EnableSortingAndPagingCallbacks="True" AllowPaging="True" 
                  AllowSorting="True" onselectedindexchanged="gvAction_SelectedIndexChanged"&gt;
                 &lt;Columns&gt;
                  &lt;asp:BoundField DataField="WFActionID" HeaderText="WFActionID" SortExpression="WFActionID" Visible="false"&gt;
                      &lt;ItemStyle HorizontalAlign="Left" Width="400px" /&gt; 
                  &lt;/asp:BoundField&gt;
                  &lt;asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description"&gt;
                      &lt;ItemStyle HorizontalAlign="Left" Width="400px" /&gt; 
                  &lt;/asp:BoundField&gt;
                 &lt;asp:CommandField  ButtonType="Button" EditText="Edit" ShowEditButton="true" /&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;/asp:Panel&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td align="left"  colspan="2"&gt;
              &lt;asp:Button ID="btnShowAddSection" runat="server" Text="" onclick="btnShowAddSection_Click"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr id="divAddEditRow" runat="server" visible="false"&gt;       
          &lt;td&gt;&lt;asp:Label ID="lblAdd" runat="server" Text="New Item: " /&gt;  
              &lt;asp:TextBox ID="txtEdit" runat="server" &gt;&lt;/asp:TextBox&gt;
          &lt;/td&gt;
          &lt;td&gt;
              &lt;asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" style="float: right; padding-right:5px; margin-right:8px"/&gt;
          &lt;/td&gt;
      &lt;/tr&gt;    
  &lt;/table&gt;
  
  &lt;asp:ObjectDataSource ID="dsStatus" runat="server" SelectMethod="FillWFStatus" UpdateMethod="UpdateWFStatus"
   TypeName="***.**.Services.WorkflowDataService" onupdating="dsStatus_Updating"&gt;
   &lt;UpdateParameters&gt;
      &lt;asp:Parameter Type="Int32" Name="WFStatusID" /&gt;
      &lt;asp:Parameter Type="String" Name="Description" /&gt;
   &lt;/UpdateParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  
   &lt;asp:ObjectDataSource ID="dsAction" runat="server" SelectMethod="FillWFAction" UpdateMethod="UpdateWFAction"
   TypeName="***.**.Services.WorkflowDataService" onupdating="dsAction_Updating"&gt;
   &lt;UpdateParameters&gt;
      &lt;asp:Parameter Type="Int32" Name="WFActionID" /&gt;
      &lt;asp:Parameter Type="String" Name="Description" /&gt;
   &lt;/UpdateParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p>CONTROL CODE BEHIND:</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {  
      }
  
  protected void gvStatus_SelectedIndexChanged(object sender, EventArgs e)
  {
      WorkflowDataService.InsertWFStatus(0, txtEdit.Text);
  }
  
  protected void gvAction_SelectedIndexChanged(object sender, EventArgs e)
  {
      WorkflowDataService.InsertWFAction(0, txtEdit.Text);
  }
  
  public bool StatusPanelMode
  {
      set { pnlStatus.Visible = !value;
      btnShowAddSection.Text = "Add New Status";
      ddlWFStatus.Visible = !value;
      }           
  }
  
  public bool ActionPanelMode
  {
      set
      {
          pnlAction.Visible = !value;
          btnShowAddSection.Text = "Add New Action";
          ddlWFAction.Visible = !value;
      }
  }
  
  protected void btnShowAddSection_Click(object sender, EventArgs e)
  {
      this.divAddEditRow.Visible = true;
      btnShowAddSection.Visible = false;
  }
  
  protected void dsStatus_Updating(object sender, ObjectDataSourceMethodEventArgs e)
  {
      var test = gvStatus.SelectedIndex;
      var test2 = dsStatus.UpdateParameters[0];
  }
  
  protected void dsAction_Updating(object sender, ObjectDataSourceMethodEventArgs e)
  {
      var test = gvStatus.SelectedIndex;
      var test2 = dsAction.UpdateParameters[0];
  }
  
  protected void btnAdd_Click(object sender, EventArgs e)
  {
      this.divAddEditRow.Visible = false;
      btnShowAddSection.Visible = true;
  
      if (pnlStatus.Visible == true)
      {
          WorkflowDataService.InsertWFStatus(0, txtEdit.Text);
          //Response.Redirect("ManageRoutingPage.aspx?tab=2");   &lt;--- This Doesnt Work                
      }
      if (pnlAction.Visible == true)
      {
          WorkflowDataService.InsertWFAction( 0, txtEdit.Text);
          Response.Redirect("ManageRoutingPage.aspx");  // &lt;-- This goes back to tab 1 instead of 3
      }
    }            
  }    
  </code></pre>