Ajax Control Toolkit 自定义选项卡扩展器用于关闭选项卡客户端

发布于 2024-09-10 12:09:17 字数 1820 浏览 8 评论 0原文

我正在尝试编写一个 AJAX 控件扩展程序,它可以修改 AJAX 控件工具包 TabPanel ,以便 TabPanel 的标题在文本后面有一个图像,当单击该图像时,使用客户端脚本隐藏选项卡标题(没有回发)。我还希望能够指定一个 onClientClose 函数,该函数在关闭选项卡时也会被调用。

我是 ASP 控件扩展程序的新手,到目前为止我已经遵循了 [教程](http://www.asp.net/ajax/tutorials/creating-a-custom-ajax-control-toolkit-control-extender-cs ASP.NET 站点上的“创建自定义 AJAX 控件工具包控件扩展器”,用于创建自定义扩展器。我将我的扩展程序称为 ClosableTabPanelExtender,并且我的扩展程序项目已构建。我设置了一个测试网页,如下所示:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:TabContainer ID="TabContainer1" runat="server">
    <asp:TabPanel ID="TabPanel0" runat="server">
        <HeaderTemplate>Tab 0</HeaderTemplate>
        <ContentTemplate>Hello!</ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel ID="TabPanel1" runat="server">
        <HeaderTemplate>Tab 1</HeaderTemplate>
        <ContentTemplate>Goodbye!</ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>
<cc1:ClosableTabPanelExtender ID="ClosableTabPanelExtender1" runat="server" 
    TargetControlID="TabPanel1" />

到目前为止,我在运行网站时收到以下错误:
“ClosableTabPanelExtender1”的 TargetControlID 无效。找不到 ID 为“TabPanel1”的控件。
该错误让我认为 TabPanel 无法扩展,所以我是否必须扩展 TabContainer

除了错误之外,我还可以使用一些指导,尤其是行为脚本。它对我来说是最难以捉摸的部分,尽管我知道它可能包含我试图添加的大部分功能。我也不确定扩展器的其他部分如何与其一起工作。

我有 Ajax Toolkit 源代码,并且浏览了 Tab 控件的源代码,我部分理解了。我还查看了控制扩展器的几个示例,主要是 Matt Berseth 的扩展器和 Dan Wahlin 的一个。

I'm attempting to write an AJAX control extender that can modify an AJAX Control Toolkit TabPanel so that the TabPanel's header has an image after the text that, when clicked, hides the tab header using client-side script (without a postback). I would also like to be able to specify an onClientClose function that is also called when a tab is closed.

I'm new to ASP control extenders, and so far I've followed the [tutorial](http://www.asp.net/ajax/tutorials/creating-a-custom-ajax-control-toolkit-control-extender-cs"Creating a Custom AJAX Control Toolkit Control Extender") on the ASP.NET site for creating a custom extender. I've called my extender a ClosableTabPanelExtender, and my extender project builds. I set up a test web page like so:

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" />
<asp:TabContainer ID="TabContainer1" runat="server">
    <asp:TabPanel ID="TabPanel0" runat="server">
        <HeaderTemplate>Tab 0</HeaderTemplate>
        <ContentTemplate>Hello!</ContentTemplate>
    </asp:TabPanel>
    <asp:TabPanel ID="TabPanel1" runat="server">
        <HeaderTemplate>Tab 1</HeaderTemplate>
        <ContentTemplate>Goodbye!</ContentTemplate>
    </asp:TabPanel>
</asp:TabContainer>
<cc1:ClosableTabPanelExtender ID="ClosableTabPanelExtender1" runat="server" 
    TargetControlID="TabPanel1" />

So far, I am getting the following error when I run the website:
The TargetControlID of 'ClosableTabPanelExtender1' is not valid. A control with ID 'TabPanel1' could not be found.
The error makes me think that a TabPanel can't be extended, so am I going to have to extend the TabContainer instead?

Apart from the error, I could use some direction, especially with the Behavior script. It is the most elusive part to me, though I know that it will likely house most of the functionality that I am trying to add. I'm also not sure how the other parts of the extender work together with it.

I have the Ajax Toolkit source code, and have looked through the source for the Tab controls, which I partially understand. I've also looked through several examples of control extenders, primarily Matt Berseth's extenders and one from Dan Wahlin.

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

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

发布评论

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

评论(1

梦幻之岛 2024-09-17 12:09:17

我终于弄清楚我需要做什么。对于对该解决方案感兴趣的任何人:

  • 为了扩展 TabPanel 控件,我必须通过覆盖扩展程序服务器代码中的 OnResolveControlID 方法来解决我发布的错误 (ClosableTabPanelExtender.cs)。

    受保护的覆盖 void OnResolveControlID(ResolveControlEventArgs e)
    {
        // 获取对包含正在扩展的 TabPanel 的最外层 TabContainer 的引用。
        TabContainer tabContainer = (TabContainer)base.FindControl(OuterTabPanelID);
        if (tabContainer != null)
        {
            // 检查是否有任何选项卡是我们正在查找的表单控件。
            foreach(tabContainer.Tabs 中的 TabPanel 选项卡)
            {
                if (tab.ID == e.ControlID)
                {
                    e.Control=选项卡;
                    返回;
                }
            }
            // 如果没有一个选项卡是我们要查找的,则搜索每个选项卡的内容。
            foreach(tabContainer.Tabs 中的 TabPanel 选项卡)
            {
                控制 ctrl = tab.FindControl(e.ControlID);
                如果(ctrl!=空)
                    返回;
            }
        }
    }
    
  • 至于扩展器的客户端Behavior脚本(以及服务器和客户端代码之间的交互,请参见此 MSDN 页面很有帮助,并且会为您省去很多麻烦。

I finally figured out what I needed to do. For anyone who is interested in the solution:

  • In order to extend the TabPanel control, I had to get around the error I posted by overriding the OnResolveControlID method in my extender's server code (ClosableTabPanelExtender.cs).

    protected override void OnResolveControlID(ResolveControlEventArgs e)
    {
        // Get a reference to the outermost TabContainer that contains the TabPanel being extended.
        TabContainer tabContainer = (TabContainer)base.FindControl(OuterTabPanelID);
        if (tabContainer != null)
        {
            // Check to see if any of the tabs are the control we are looking form.
            foreach (TabPanel tab in tabContainer.Tabs)
            {
                if (tab.ID == e.ControlID)
                {
                    e.Control = tab;
                    return;
                }
            }
            // If none of the tabs are what we are looking for, search the contents of each tab.
            foreach (TabPanel tab in tabContainer.Tabs)
            {
                Control ctrl = tab.FindControl(e.ControlID);
                if (ctrl != null)
                    return;
            }
        }
    }
    
  • As for the client-side Behavior script of the extender (and the interaction between the server and client code, the articles listed on this MSDN page are helpful and will save you a lot of trouble.

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