问题
I have a set of tabs in a tab container that I can move between freely by manually clicking on the tabs or by using a javascript; however, what I want to do is to switch between tabs using an ASP.NET serverside button.
So here's the layout. Tab 1 has an ASP.NET Button, which, when clicked, should go to Tab 2 and display the results of a query in a gridview. Here is the onclick code for the ASP.NET Button:
protected void btnOutstandingTasks_Click(object sender, EventArgs e)
{
try
{
// Load task list by all outstanding tickets
SqlDSOutstanding.SelectParameters.Clear();
SqlDSOutstanding.SelectParameters.Add("1", TypeCode.Int64, "3");
gvxTaskList.DataSourceID = null;
gvxTaskList.DataSource = SqlDSOutstanding;
gvxTaskList.DataBind();
upnlTaskList.Update();
DispatchTabs.ActiveTabIndex = DispatchTabs.ActiveTabIndex + 1;
}
catch (Exception ex)
{
}
}
Not sure why its not working, but i imagine someone out there knows how to do it. Appreciate the help!
And here is the client side showing that the tab container is inside an update panel.
<asp:UpdatePanel ID="upnlDispatch" UpdateMode="Conditional" runat="server">
<Triggers></Triggers>
<ContentTemplate>
<ajaxToolkit:TabContainer ID="DispatchTabs" runat="server" Height="100%" Width="100%" CssClass="Tab" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="tabDashboard" runat="server" HeaderText="Dashboard" Width="100%" Height="100%">
<HeaderTemplate>
Dashboard
</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="upnlDashboard" UpdateMode="Conditional" runat="server">
<ContentTemplate>
回答1:
Putting the tab container within an update panel should do the trick. Also, currently your code has a flaw, you don't want to always just add 1 to the ActiveIndex tab because you will get an out of range exception if you go beyond the last one.
if(DispatchTabs.ActiveTabIndex == DispatchTabs.Count() -1)
{
DispatchTabs.ActiveTabIndex = 0;
}
else
{
DispatchTabs.ActiveTabIndex = DispatchTabs.ActiveTabIndex + 1;
}
来源:https://stackoverflow.com/questions/12921526/how-can-i-switch-to-a-different-ajax-on-a-click-of-an-asp-net-button-server-side