开发者

How to insert the ClientID of a div into an OnClientClick event

开发者 https://www.devze.com 2022-12-31 22:19 出处:网络
In the XHTML for a page I have:- <asp:Button ID=\"bookNowButton\" runat=\"server\" CssClass=\"bookNowButton\"

In the XHTML for a page I have:-

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

This breaks. I need开发者_Python百科 the correct syntax or method to insert the bookingFormDiv.ClientID into the control.

What needs to be done?


You can set the attribute from code behind:

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


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消