如何获取 ajax 手风琴的点击事件? ASP.NET
我有一个 ajax 手风琴,每个窗格都包含一个 updatepanel (动态创建)。我希望单击窗格标题时刷新更新面板,但没有单击事件。
我可以在标题中弹出一个按钮,并使用脚本管理器将其注册为异步触发器,但我不需要按钮,我希望整个标题都是触发器。
我看不到将 div 或标签设置为触发器的方法,因为它们没有服务器端单击事件。我还有其他方法可以做到吗?
I have an ajax accordion, and each pane contains an updatepanel (created dynamically). I want the updatepanels to refresh when the header of the pane is clicked, but there is no click event.
I can pop a button in the header, and register it as an asynch trigger using the scriptmanager, but I don't want a button, I want the entire header to be a trigger.
I can't see a way to set a div or a label as a trigger as they don't have a server side click event. Is there some other way I can do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 jQuery。
语法如下所示简单:
有时,对于 ASP.NET,我必须使用通配符 ID 匹配,因为 ASP.NET 会为您的元素创建非常长的半随机客户端 ID。您可以执行如下操作:
本质上,您可以选择 DOM 上的任何内容并使用 jQuery 将事件处理程序附加到它。有时您必须对选择器发挥创意。
重要提示:如果您使用 updatepanels 并且要监视单击的标题位于该面板内部,则在通过 ajax 加载/重新加载面板后,您需要将这些事件处理程序重新绑定到您选择的元素。这可以使用以下代码来实现:
Use jQuery.
The syntax would be as easy as the following:
Sometimes with ASP.NET I have had to use a wildcard ID match because ASP.NET creates really long semi-random clientside ID's for your elements. You would do something like the following:
Essentially you can select anything on the DOM and attach an event handler to it with jQuery. Sometimes you have to get creative with the selectors.
IMPORTANT: If you are using updatepanels and the heading you want to monitor for a click is inside that panel, you will need to REBIND those event handlers to the element you are selecting after the panel is loaded/re-loaded via ajax. This can be achieved using the following code: