我想知道是否有人可以帮助我。我有三个TabPanels,具体取决于点击了哪个标签我想调用不同的c#函数来显示不同的内容。我知道我可以在页面加载时运行所有功能,但这看起来很混乱。我确信有办法做到这一点,但我看起来并不多。我可能会从完全错误的角度考虑这个问题,所以如果你能想出更好的方法,请告诉我。
非常感谢任何帮助!
示例ASP.net
<ajaxToolkit:TabContainer ID="tabParameters" AutoPostBack="true" Width="100%" runat="server" ActiveTabIndex="0">
<ajaxToolkit:TabPanel ID="tabDetails" OnClientClick="Load_Details()" HeaderText="Details" runat="server">
答案 0 :(得分:1)
我会将“函数”嵌套到WebUserControls中并将它们放入单独的TabPanels中。他们在Page.Load上什么都不做,也是隐形的。定义一个执行所有DataBinding / Time消耗的函数“BindData”。当用户更改ActiveTab(或默认活动选项卡)时,使UserControl可见并调用其BindData函数。
您需要UserControl周围的UpdatePanels(Updatemode = Conditional)和Eventname = ActiveTabChanged的Async-Postback-Trigger,以便只重新加载此Panel。
例如在ASPX上(MD_Location是UserControl,由于空间不足我只发布一个,但你必须想象很多):
<act:TabContainer ID="TabContainer1" runat="server" AutoPostBack="true" >
<act:TabPanel ID="TabLocation" runat="server" HeaderText="Locations">
<ContentTemplate>
<asp:UpdatePanel ID="UpdLocation" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<MD:MD_Location id="MD_Location" runat="server" Visible="false" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="TabContainer1" EventName="ActiveTabChanged" />
</Triggers>
</asp:UpdatePanel>
</ContentTemplate>
</act:TabPanel>
并且在Codebehind中(对不起,只有VB.Net可用,我希望你能得到这个想法):
Private Sub TabContainer1_ActiveTabChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabContainer1.ActiveTabChanged
If Me.TabContainer1.ActiveTab Is Me.TabLocation Then
Me.MasterDataType = "Locations"
End If
switchControlVisibility()
End Sub
Private Sub switchControlVisibility()
Select Case Me.MasterDataType.ToLower
Case "locations"
Me.MD_Location.Visible = True
Me.Lblheader2.Text = "Locations"
UpdHeader.Update()
Me.MD_Location.BindData() '<---- do time-consuming stuff
Me.UpdLocation.Update()
End Sub
示例