如何将 div 的 ClientID 插入到 OnClientClick 事件中

发布于 2024-09-03 09:20:29 字数 288 浏览 4 评论 0原文

在页面的 XHTML 中,我有:-

<asp:Button ID="bookNowButton" runat="server" CssClass="bookNowButton"
            OnClientClick="showHideLoggedInDiv('<%=bookingFormDiv.ClientID%>')" />

这会破坏。我需要正确的语法或方法将 bookingFormDiv.ClientID 插入控件中。

需要做什么?

In the XHTML for a page I have:-

<asp:Button ID="bookNowButton" runat="server" CssClass="bookNowButton"
            OnClientClick="showHideLoggedInDiv('<%=bookingFormDiv.ClientID%>')" />

This breaks. I need the correct syntax or method to insert the bookingFormDiv.ClientID into the control.

What needs to be done?

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

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

发布评论

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

评论(3

网名女生简单气质 2024-09-10 09:20:29

您可以从后面的代码设置属性:

bookNowButton.OnClientClick = "showHideLoggedInDiv('" + bookingFormDiv.ClientID + "')"

You can set the attribute from code behind:

bookNowButton.OnClientClick = "showHideLoggedInDiv('" + bookingFormDiv.ClientID + "')"
少女七分熟 2024-09-10 09:20:29

因为这是正确的语法,所以我会开始在其他地方寻找,什么是 bookingFormDiv,它是带有 id bookingFormDiv 的服务器端控制(runat=server)吗?

编辑

意识到这是在服务器端控件(asp:Button)内,因此您不能使用该语法,接受的答案是正确的。

As this is the correct syntax i would start looking elsewhere, what is bookingFormDiv, is it server side control (runat=server) with the id bookingFormDiv?

edit

realised this is within a server side control (asp:Button) so you cannot use that syntax, the accepted answer is correct.

空城旧梦 2024-09-10 09:20:29

删除 runat="server",然后将 asp:Button 替换为 input type="button",将 OnClientClick 替换为onclick

Remove runat="server", then replace asp:Button with input type="button" and OnClientClick with onclick.

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