I am creating a control ascx
that will have multiple impressions on a same page.
In this control, there is an image that I want to execute a javascript
function when it is clicked. For example, like this:
<asp:Panel ID="divPai" runat="server" >
<div>
<div ...>
<input .../>
</div>
<asp:Image ID="btnMensagem"
Class="animated-transition rotate-90-degrees"
ImageUrl="../../Images/bt_proximo.png"
onclick="mostrarAlerta2();"
runat="server"
Style="padding:10px;"/>
</div>
<div class="div-manipulavel" ...>
<input ... />
</div>
</asp:Panel>
In a separate js
file file I have all the functions I need to use in this control and the inclusion of this script is occurring normally.
I made the script import like this:
Page.ClientScript.RegisterClientScriptInclude(GetType(), "scriptsMeuControle", ResolveClientUrl("~/Componentes/Scripts/MeuControle.js"));
This would be the content file:
function mostrarAlerta(mensagem)
{
alert('Conteúdo: ' + mensagem);
}
function mostrarAlerta2()
{
alert('Função acionada!');
}
The problem happens when I need to pass a parameter to execute in the function, as is the case of mostrarAlerta(mensagem)
.
I tried this way:
<asp:Image ID="btnMensagem"
...
onclick="mostrarAlerta2('<% =divPai.ClientID %>');"/>
This does not work. The expression <% =divPai.ClientID %>
is not interpreted and the content that I tried to pass is displayed literally:
Conteúdo: <% =divPai.ClientID %>
How do I pass a parameter that is interpreted server-side like this to a javascript
function?