开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜