存储TabContainer的ActiveTabIndex回发

编程入门 行业动态 更新时间:2024-10-22 20:27:49
本文介绍了存储TabContainer的ActiveTabIndex回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在应用程序中经常使用AJAX控件工具包的 TabContainer控件,并且该应用程序的要求是将活动标签存储在会话中。当前要执行此操作,我将选项卡放在UpdatePanel中,并在更改选项卡时执行回发以将活动选项卡索引存储在会话中。这是一个缓慢的操作,因为页面非常密集,因此不理想。有其他选择吗?

I use the AJAX Control Toolkit's 'TabContainer' control a lot in my application, and a requirement of the application is to store the active tab in a Session. To do this currently, I have the tabs in an UpdatePanel, and perform a postback to store the active tab index in a session when the tabs are changed. This is a slow operation as the page is fairly intensive so this is not ideal. Are there any alternatives to this? Perhaps using a web service to store the session without a post back?

推荐答案

最简单的方法是使用ScriptManager的PageMethod。

The simplest way is using of ScriptManager's PageMethod.

1启用页面方法

<asp:ScriptManager runat="server" EnablePageMethods="true"></asp:ScriptManager>

2在aspx-page中创建可获取实际标签信息的页面方法

2 Create pagemethod within aspx-page that'll get actual tab info

[WebMethod] public static void SaveCurrentTab(string controlId, int currentTabIndex) { // save data to session }

3创建用于将实际数据发送到服务器的js函数处理程序

3 Create js-function handler for sending actual data to server

<script type="text/javascript"> function clientActiveTabChanged(sender, args) { PageMethods.SaveCurrentTab(sender.get_id(), sender.get_activeTabIndex()); } </script>

4将js处理程序附加到TabContainer

4 Attach js-handler to TabContainer

<ajaxToolkit:TabContainer ID="TabContainer1" runat="server" OnClientActiveTabChanged="clientActiveTabChanged"> <ajaxToolkit:TabPanel ID="TabPanel1" runat="server" HeaderText="Test1"> <ContentTemplate>Test1</ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel2" runat="server" HeaderText="Test2"> <ContentTemplate>Test2</ContentTemplate> </ajaxToolkit:TabPanel> <ajaxToolkit:TabPanel ID="TabPanel3" runat="server" HeaderText="Test3"> <ContentTemplate>Test3</ContentTemplate> </ajaxToolkit:TabPanel> </ajaxToolkit:TabContainer>

PS还有另一种决定-将客户端数据保存在 cookie 。

PS There is alternative decision - saving data on client side in cookie.

更多推荐

存储TabContainer的ActiveTabIndex回发

本文发布于:2023-11-25 02:14:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627905.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TabContainer   ActiveTabIndex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!