c# – Two parameters with String.Format in an asp:HyperLink

Question:

I would like to send the parameters (database ID, ClientID) in an <asp:Hyperlink . I wanted the end result to be:

<a id="ctl00" onclick="OpenModal(704520,'asdf_ID_DaImageAbaixo')">
    <img id="ID_IMAGE" src="../online/img_admin/icon_hist.gif" />
</a>

But I can't do 2 things. First the single quote is not working.

String.Format("AbreModal({0},'{1}')",

Give unformatted Tag with these single quotes. Without them it works, but then it doesn't close in JavaScript.

Second: I can't capture the ID of the image below and send it on this link, I'm trying to:

<asp:HyperLink ID="HyperLink4" runat="server" onclick='<%# String.Format("AbreModal({0},{1})", DataBinder.Eval(Container.DataItem, "intid"),"123" ) %>'>
 <asp:Image ID="img_Historico" runat="server" ImageUrl="../online/img_admin/icon_hist_off.png" />
</asp:HyperLink>

How to send?

Answer:

Try something like this:

<asp:HyperLink ID="HyperLink4" runat="server" onclick="<%# String.Format("AbreModal({0},\"{1}\"",val1,val2) %>">
   <asp:Image ID="img_Historico" runat="server" ImageUrl="../online/img_admin/icon_hist_off.png" />
</asp:HyperLink>

Replacing val1 with your DataBind and val2 with the ID value

Scroll to Top