How to insert ClientID in OnClientClick event

In XHTML for the page I have: -

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

It is interrupted. I need the correct syntax or method to insert the bookingFormDiv.ClientID into the control.

What should be done?

+4
source share
3 answers

You can set the attribute from the code behind:

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

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

change

realized that this is inside the server-side control (asp: Button), so you cannot use this syntax, the correct answer is correct.

0
source

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

0
source

Source: https://habr.com/ru/post/1310975/


All Articles