0

Can anyone offer an explanation as to why the asp:imagebutton gives me a badly formed html error while the html input element does not? I know it's about the findcontrol() in the onclientclick assignment. They're written in exactly the same format but maybe they shouldn't be?

 <ItemTemplate>
     <input type="image" src="Resources/info.png"         onclick="toggle('<%# Container.FindControl("PresetUploadDescription").ClientID %>');return false;" /> 
     <asp:ImageButton ImageUrl="Resources/info.png" OnClientClick="toggle('<%# Container.FindControl("PresetUploadDescription").ClientID %>');return false;" ToolTip="info" ID="Description" runat="server"/>
.... 
Gio
  • 4,099
  • 3
  • 30
  • 32

1 Answers1

0

You cannot use a <%...%> construct in a control that is executed at the server. (runat="server")

<%#...%> is used for databinding or Eval type statements.

<%=...%> is equivalent to a Response.Write statement, which looks like what you are trying to do (write out the ClientID of a certain control). Unfortunately, this won't work either - you'll get a

Server tags cannot contain <% ... %> constructs. Error

To fix, you need to Add the OnClientClick attribute to the Imagebutton control via the Code Behind page:

Description.Attributes.Add("OnClientClick", 
"toggle('" + FindControl("PresetUploadDescription").ClientID + "');return false;");
OpenR
  • 186
  • 1
  • 11