Ajax Tab 控件中的 Tab 更改事件

发布于 2024-12-08 13:49:40 字数 1931 浏览 0 评论 0原文

我在我的一个页面中使用了 Ajax Tab Control。它有一个主用户控件,其中包含三个选项卡。 这三个选项卡由三个单独的用户控件填充。 这些用户控件有一些控件和一个用于保存数据的保存按钮。 我的问题是,如果用户在当前选项卡用户控件中有任何未保存的更改,我必须阻止用户离开选项卡。我必须在弹出窗口中询问他您有未保存的更改,是否要保存它们。并且根据用户的反应必须跟进进一步的行动。 我可以使用 TabControl 的 OnClientActiveTabChanged 事件打开弹出窗口并询问未保存的更改。我面临着确切知道哪个选项卡的数据未保存的问题。我无法追踪用户试图离开的当前选项卡。任何人都可以帮助我始终维护当前选项卡的名称,以便每当用户单击任何其他选项卡时我都会知道我要浏览哪个选项卡的数据必须保存并可以从我的主用户控件中触发相应用户控件的保存功能。

请查找以下代码示例:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MasterUserControl.ascx.cs"
    Inherits="TabbedSolution.MasterUserControl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="UserControl1.ascx" TagName="UserControl1" TagPrefix="uc1" %>
<%@ Register Src="UserControl2.ascx" TagName="UserControl2" TagPrefix="uc2" %>
<%@ Register Src="UserControl3.ascx" TagName="UserControl3" TagPrefix="uc3" %>
<div>
    <asp:TabContainer ID="TabContainer1" runat="server" 
    AutoPostBack="true" OnClientActiveTabChanged="chechUnsavedChanges" OnActiveTabChanged="tabChanged">
        <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Panel1" >
            <ContentTemplate>
                <uc1:UserControl1 ID="UserControl11" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="Panel2">
            <ContentTemplate>
                <uc2:UserControl2 ID="UserControl21" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="Panel3">
            <ContentTemplate>
                <uc3:UserControl3 ID="UserControl31" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
    </asp:TabContainer>
</div>

I have used Ajax Tab Control in one of my pages. It has got a master User Control with three tabs in it.
Those three tabs have been populated by three separate user controls.
Those user controls have some controls and a save button to save data.
My problem is that, I have to stop a user from navigating away from a tab if he has any unsaved changes in the current tabs User control. I have to ask him in a pop up that you have unsaved changes, would you like to save them. And according to response of user have to follow up with further action.
I am able to open Pop up and ask about unsaved changes using OnClientActiveTabChanged event of TabControl. I am facing issue in knowing exactly which tab's data is unsaved. I am not able to track down current tab, from which user is trying to navigate away.Can anybody help me out in maintaining current tab's name all the time, so that whenever user clicks on any other tab i will be knowing which tab's data I have to save and could fire save function of the appropriate user control from my Master User control.

Please find below code sample for the same:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MasterUserControl.ascx.cs"
    Inherits="TabbedSolution.MasterUserControl" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="UserControl1.ascx" TagName="UserControl1" TagPrefix="uc1" %>
<%@ Register Src="UserControl2.ascx" TagName="UserControl2" TagPrefix="uc2" %>
<%@ Register Src="UserControl3.ascx" TagName="UserControl3" TagPrefix="uc3" %>
<div>
    <asp:TabContainer ID="TabContainer1" runat="server" 
    AutoPostBack="true" OnClientActiveTabChanged="chechUnsavedChanges" OnActiveTabChanged="tabChanged">
        <asp:TabPanel ID="TabPanel1" runat="server" HeaderText="Panel1" >
            <ContentTemplate>
                <uc1:UserControl1 ID="UserControl11" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel2" runat="server" HeaderText="Panel2">
            <ContentTemplate>
                <uc2:UserControl2 ID="UserControl21" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
        <asp:TabPanel ID="TabPanel3" runat="server" HeaderText="Panel3">
            <ContentTemplate>
                <uc3:UserControl3 ID="UserControl31" runat="server" />
            </ContentTemplate>
        </asp:TabPanel>
    </asp:TabContainer>
</div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑看君怀她人 2024-12-15 13:49:40

在你的 tabchanged javascript 函数中尝试这个

var container = $find('TabContainer1');
var activeTab = container.get_activeTabIndex(); 

我不知道没有 jquery 的方法,但是为什么使用没有 jquery 的 javascript 呵呵:)

ps: 我还没有测试过这个解决方案,但它应该可以工作

Try This in your tabchanged javascript function

var container = $find('TabContainer1');
var activeTab = container.get_activeTabIndex(); 

I don't know the way without jquery, but why use javascript without jquery huh :)

ps: I haven't tested this solution, but it should work

辞别 2024-12-15 13:49:40

在我看来,如果您可以获取当前活动选项卡索引并将其存储在会话中,那应该可行。这就是我为 asp.net 控件的多视图 act​​iveviewindex 等 onclick 事件所做的事情。我获取页面加载完成事件上的值以保存用户刷新时的当前视图等。

我发现使用带有更新面板的多视图和一点图形天才使其看起来像一个选项卡,您可以制作一个选项卡控件可以有可点击的链接按钮,这样你就可以这样设置会话......设置 onclick 并在加载完成时检索。

前任:
Session("whichTab") = myTabControl.activetabindex 单击并
当前页面加载完成时 whatever = Session("whichTab")

注意:我在 VB.net 中完成所有这些操作,

这背后的代码会告诉您当用户更改选项卡时他或她之前所在的选项卡。当然,您必须找到为您的应用程序执行此操作的最佳方法,并查看选项卡控件选项卡如何似乎没有服务器端单击事件,我改为使用多视图。如果有人可以纠正我的点击事件,请这样做。尽管我刚刚开始使用它,但我还没有真正查看过该控件的规格,这也是我到达这里的原因。

希望这有帮助。

It seems to me that if you could get the current active tab index and store it in session, that should work. This is what I do for multiview activeviewindex etc. onclick events for asp.net controls. I get the values on the page load complete event to save users current view on refresh etc.

I have found that using the multiview with an update panel and a little graphic genious to make it look like a tab, you can make a tab control that can have clickable link buttons so you can set the session this way.... set onclick and retrieve on load complete.

EX:
Session("whichTab") = myTabControl.activetabindex on click and
whatever = Session("whichTab") on load complete for curent page.

NOTE: I do all of this in VB.net code behind

this will tell you when the user changes tabs which one was he or she previously at. Naturally, you would have to find the best way to do this for your app and seeing how the tab controls tabs don't seem to have a serverside click event, I do the multiview instead. If someone can correct me on the click event please do. I haven't really looked at the specs for the control though I just started using it and is how I got here.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文