Ajax Control Toolkit 自定义选项卡扩展器用于关闭选项卡客户端
我正在尝试编写一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于弄清楚我需要做什么。对于对该解决方案感兴趣的任何人:
为了扩展 TabPanel 控件,我必须通过覆盖扩展程序服务器代码中的
OnResolveControlID
方法来解决我发布的错误 (ClosableTabPanelExtender.cs
)。至于扩展器的客户端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
).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.