AjaxControlToolkit TabContainer 准备好时的 Javascript 吗?
我有一个带有 TabContainer
控件(来自 Ajax Control Toolkit)的页面,我根据当前选择的选项卡切换页面上某些元素的可见性。我一直在 OnClientActiveTabChanged 的事件处理程序中执行此操作(效果很好),但我发现它在回发后使页面处于错误状态。我尝试向 document.ready
事件处理程序添加一些代码来获取索引,但是当我执行以下操作时:
$(document).ready(function () {
var index = $('#<%= TabContainer1.ClientID %>').[0].control.get_activeTabIndex();
// Do some stuff with the index
});
...我在 .control
财产。有没有办法为 TabContainer
挂钩客户端“就绪”事件?
我不熟悉普通 DOM 元素的事件生命周期(似乎应该有一个通用的 onload 事件,但我没有看到)。如果没有可以轻松处理的事件,似乎可以添加一个带有 UpdateMode=Conditional 的 UpdatePanel
和一个指向带有 onclick 事件处理程序的隐藏按钮的 AsyncPostBackTrigger获取活动选项卡索引——但这对于我期望 DOM 已经公开的东西来说似乎有很多移动部分。
I have a page with a TabContainer
control (from the Ajax Control Toolkit), and I toggle the visibility of some elements on the page depending on the currently-selected tab. I'd been doing this in an event handler for OnClientActiveTabChanged
(which works fine), but I discovered that it leaves the page in the wrong state after a postback. I tried adding some code to the document.ready
event handler to get the index, but when I do the following:
$(document).ready(function () {
var index = $('#<%= TabContainer1.ClientID %>').[0].control.get_activeTabIndex();
// Do some stuff with the index
});
...I get a null reference exception on the .control
property. Is there a way to hook a client-side "ready" event for the TabContainer
?
I’m not familiar with the event lifecycle with normal DOM elements (it seems like there ought to be a general onload event, but I don’t see one). If there isn’t an event that can be easily handled, it seemed like it might work to add an UpdatePanel
with UpdateMode=Conditional and an AsyncPostBackTrigger that pointed to a hidden button with an onclick event handler that would get the active tab index – but that seems like a lot of moving pieces for something that I’d expect the DOM to expose already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为时已晚,无法提供帮助,但我遇到了同样的问题并找到了解决方法。
将您的代码更改
为
此处的说明:
http://encosia.com/document-ready-and- pageload-are-not-the-same/
基本上,jQuery的ready事件“有点早”,TabContainer还没有初始化,而客户端ASP.Net的pageLoad已经足够晚了,TabContainer已经初始化到那时。
Too late to be helpful, but I've had the same issue and found a workaround.
Change you code
to
Explanation here:
http://encosia.com/document-ready-and-pageload-are-not-the-same/
Basically, jQuery's ready event is "a bit early" and the TabContainer is not initialized yet, whereas the client side ASP.Net's pageLoad is late enough and the TabContainer has been initialized by then.
检查这篇文章以保存选项卡选择在回发期间。它通过将活动选项卡索引保存在隐藏变量中来适用于正常回发。虽然它是为发布的链接中的 JQuery 插件编写的,但概念应该是相同的,即保留所选选项卡的索引。
Check this post to save tab selection during postbacks. It works for normal post backs by saving the active tab index in hidden variable. Though its written for a JQuery plugin in the posted link, concept should be the same i.e., persisting the index of the selected tab.