Problem when writing quotes in HTML

0

I have the following HTML code from an ImageButton.

<asp:UpdatePanel runat="server">
    <ContentTemplate>
       <asp:DataList ID="dlImagenes" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" HorizontalAlign="Center" PagedControlID="dlImagenes">
             <ItemTemplate>
                <asp:ImageButton ID="imgValidarImagenes" runat="server" Width="200px" Height="150px" ImageUrl='<%# Bind("imagen") %>' OnClick='<%# "popImage('" + Bind("imagen") + "', Validar imagen)"%>' CommandArgument='<%# Container.ItemIndex %>' />
             </ItemTemplate>                                                                                                    
       </asp:DataList>
     </ContentTemplate>
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="dlImagenes"/>
     </Triggers>
</asp:UpdatePanel>

And I have the following error:

  

ASP.NET error at runtime: A call to Bind must be assigned to a property of a control within a template.
  I think it's because the quotes on the property of the popImage function of the onClick event are misplaced.
  I tried several ways but I still can not find the correct way to write it.
  The following are the codes that did not work for me:

OnClick='popImage('<%# Bind(\"imagen\") %>', Validar imagen)'

OnClick='popImage('<%# Bind(&quot;imagen&quot;) %>', Validar imagen)'  

Could it be that you are tackling the problem badly?

    
asked by Pablo Matias 25.06.2018 в 17:34
source

1 answer

0

The problem is that the bindeo is not correct. When you do the binding of an attribute you have to do the binding of the complete attribute. In this <%# %> behaves different from the <%= %> (which is a Response.Write).

On the other hand you have to user the property OnClientClick .

The correct way to do the bind is:

OnClientClick='<%# "popImage('" + Bind("imagen") + "', 'Validar imagen')"%>'
    
answered by 25.06.2018 в 17:40