5

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?

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Craig
  • 1,704
  • 1
  • 18
  • 36

3 Answers3

6

You can set the attribute from code behind:

bookNowButton.OnClientClick = "showHideLoggedInDiv('" + bookingFormDiv.ClientID + "')"
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • That worked nicely thanks. Unfortunately it causes a form post. How do I stop it? I should explain I'm changing an html tag into an 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
0

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
  • 6,081
  • 1
  • 26
  • 39
0

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

Denis
  • 3,653
  • 4
  • 30
  • 43