我在应用程序中经常使用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回发
发布评论