如何响应重定向到选项卡容器中的面板或控件

时间:2012-07-16 13:18:14

标签: c# asp.net tabs panel response.redirect

我正在制作一个标签页(4个标签 - 标签容器),其中2个使用相同的控件,并且具有不同的网格视图和不同的dats源,可以编辑和添加项目。

编辑和添加项目工作正常,但是当我添加项目时,gridview或页面需要刷新以显示新项目。使用Response.Redirect仅刷新页面并重定向到第一个选项卡。我正在制作选项卡2和3,重定向需要指向相关选项卡,而不是第一个选项卡。

有关如何执行此操作的任何建议吗?

我正在使用Visual Studio 2010,C#ASP.Net

CODE:

PAGE:

<asp:Content ID="Content2" ContentPlaceHolderID="pnlMainContent" runat="server">
<div style="padding: 10px">
    <cc1:TabContainer ID="tbMain" runat="server" ActiveTabIndex="0" Width="100%" AutoPostBack="true"
        OnActiveTabChanged="tbMain_ActiveTabChanged">
        <cc1:TabPanel runat="server" ID="tbpgWFTypes" HeaderText="Work Flow Types">
            <ContentTemplate>
                <table style="width: 100%">
                    <tr>
                        <td align="center">
                             <uc1:ctrlWorkflowTypeControl ID="ctrlWorkflowTypeControl" runat="server" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel runat="server" ID="tbpgWFStatus" HeaderText="Work Flow Status">
            <ContentTemplate>
                <table style="width: 100%">
                    <tr>
                        <td align="center">
                            <uc2:ctrlStatusControl ID="ctrlStatusControl" runat="server" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel runat="server" ID="tbpgWFActions" HeaderText="Work Flow Actions">
            <ContentTemplate>
                <table style="width: 100%">
                    <tr>
                        <td align="center">
                            <uc3:ctrlActionControl ID="ctrlActionControl" runat="server" />                                
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
        <cc1:TabPanel runat="server" ID="tbpgWFRouting" HeaderText="Work Flow Routing">
            <ContentTemplate>
                <table style="width: 100%">
                    <tr>
                        <td align="center">
                           <uc4:ctrlWorkflowRoutingControl ID="ctrlWorkflowRoutingControl" runat="server" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </cc1:TabPanel>
    </cc1:TabContainer>
</div>

背后的代码:

 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);
    }
  }
}

CONTROL:

    <table>
    <tr>
        <td align="left" colspan="2">
            <asp:DropDownList ID="ddlWFStatus" runat="server" Width="400px" DataSourceID="dsStatus" DataTextField="Description" Visible="false"></asp:DropDownList>
            <asp:DropDownList ID="ddlWFAction" runat="server" Width="400px" DataSourceID="dsAction" DataTextField="Description" Visible="false"></asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td  colspan="2"></td>
    </tr>
    <tr>
        <td align="left"  colspan="2">
        <asp:Panel ID="pnlStatus" runat="server" Visible="false">
            <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">
               <Columns>
                <asp:BoundField DataField="WFStatusID" HeaderText="WFStatusID" SortExpression="WFStatusID" Visible="false">
                    <ItemStyle HorizontalAlign="Left" Width="400px" /> 
                </asp:BoundField>
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description">
                    <ItemStyle HorizontalAlign="Left" Width="400px" /> 
                </asp:BoundField>
               <asp:CommandField  ButtonType="Button" EditText="Edit" ShowEditButton="true" />
               </Columns>
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
            </asp:Panel>
             <asp:Panel ID="pnlAction" runat="server" Visible="false">
            <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">
               <Columns>
                <asp:BoundField DataField="WFActionID" HeaderText="WFActionID" SortExpression="WFActionID" Visible="false">
                    <ItemStyle HorizontalAlign="Left" Width="400px" /> 
                </asp:BoundField>
                <asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description">
                    <ItemStyle HorizontalAlign="Left" Width="400px" /> 
                </asp:BoundField>
               <asp:CommandField  ButtonType="Button" EditText="Edit" ShowEditButton="true" />
               </Columns>
              <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                <EditRowStyle BackColor="#999999" />
                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            </asp:GridView>
            </asp:Panel>
        </td>
    </tr>
    <tr>
        <td align="left"  colspan="2">
            <asp:Button ID="btnShowAddSection" runat="server" Text="" onclick="btnShowAddSection_Click"/>
        </td>
    </tr>
    <tr id="divAddEditRow" runat="server" visible="false">       
        <td><asp:Label ID="lblAdd" runat="server" Text="New Item: " />  
            <asp:TextBox ID="txtEdit" runat="server" ></asp:TextBox>
        </td>
        <td>
            <asp:Button ID="btnAdd" runat="server" Text="Add" onclick="btnAdd_Click" style="float: right; padding-right:5px; margin-right:8px"/>
        </td>
    </tr>    
</table>

<asp:ObjectDataSource ID="dsStatus" runat="server" SelectMethod="FillWFStatus" UpdateMethod="UpdateWFStatus"
 TypeName="***.**.Services.WorkflowDataService" onupdating="dsStatus_Updating">
 <UpdateParameters>
    <asp:Parameter Type="Int32" Name="WFStatusID" />
    <asp:Parameter Type="String" Name="Description" />
 </UpdateParameters>
</asp:ObjectDataSource>

 <asp:ObjectDataSource ID="dsAction" runat="server" SelectMethod="FillWFAction" UpdateMethod="UpdateWFAction"
 TypeName="***.**.Services.WorkflowDataService" onupdating="dsAction_Updating">
 <UpdateParameters>
    <asp:Parameter Type="Int32" Name="WFActionID" />
    <asp:Parameter Type="String" Name="Description" />
 </UpdateParameters>
</asp:ObjectDataSource>

背后的控制代码:

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");   <--- This Doesnt Work                
    }
    if (pnlAction.Visible == true)
    {
        WorkflowDataService.InsertWFAction( 0, txtEdit.Text);
        Response.Redirect("ManageRoutingPage.aspx");  // <-- This goes back to tab 1 instead of 3
    }
  }            
}    

1 个答案:

答案 0 :(得分:4)

您可以将查询字符串用于此目的,例如

Response.Redirect("default.aspx?tab=1");
Response.Redirect("default.aspx?tab=2");
Response.Redirect("default.aspx?tab=3");

在default.aspx页面中。你可以做点什么

var tab = Request.QueryString["tab"];
switch(tab)
{
case "1":
//Bind data for first tab
break;
case "2":
//Bind data for second tab
break;
}

希望有所帮助:)