Take the 2-minute tour ×

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?

share|improve this question
Please show a bit more code for context. –  Robert Massa May 26 '10 at 14:19
what is rendered to HTML? this looks ok to me –  Pharabus May 26 '10 at 14:24
Including how it breaks (the error message) would be helpful. –  AaronSieb May 26 '10 at 14:39
add comment

2 Answers

up vote 6 down vote accepted

You can set the attribute from code behind:

bookNowButton.OnClientClick = "showHideLoggedInDiv('" + bookingFormDiv.ClientID + "')"
share|improve this answer
That worked nicely thanks. Unfortunately it causes a form post. How do I stop it? I should explain I'm changing an html <input /> tag into an <asp:Button></Button> tag. All the button does is open and close a Div. I don't want it to do anything else. Thanks –  Craig May 26 '10 at 14:39
@Craig That's the default behavior of the button. You can return false from the OnClientClick to prevent that. There might also be a property along the lines of CausesPostback on the button, but I'm too lazy to look. –  AaronSieb May 26 '10 at 14:41
Thanks for that. It led me to set UseSubmitBehavior = "False". So all done;) Thanks very much. –  Craig May 26 '10 at 15:06
add comment

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?


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

share|improve this answer
add comment

Your Answer


