views:

170

answers:

2

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?

+5  A: 

You can set the attribute from code behind:

bookNowButton.OnClientClick = "showHideLoggedInDiv('" + bookingFormDiv.ClientID + "')"
Guffa
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
@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
Thanks for that. It led me to set UseSubmitBehavior = "False". So all done;)Thanks very much.
Craig
A: 

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.

Pharabus