Data-Bind and Onclick on the same button

Asked

Viewed 57 times

1

I have a button that has a data-bind, calling a function JS that is working perfectly.

However, I need to call another function on the same button, only on C#, in class CSS of my page, if I leave the data-bind and the onclick, only the data-bind works, but if I take the data-bind, the onclick works normally. Follows code:

<asp:LinkButton ID="btnBuscar" runat="server" onclick="btnVisualizar_Click" 
    Text="Buscar" class="btn btn-info" data-bind="click: buscar"/>

In that case, only the data-bind is being called, the onclick doesn’t work. It is worth noting that if I take the data-bind, the other function works normally.

  • 5

    If you need to call both functions, I think you can call the second function in the first function to be called in JS.

  • I understand @Edwardramos, but how could I call the other function? I can send the function I use in js stating that it is a function that calls the google map.

  • Apparently so...

1 answer

1

You can call the second function within the first function (I think this will solve your problem), if that’s it, try to do so:

<asp:LinkButton ID="btnBuscar" runat="server" onclick="btnVisualizar_Click" 
    Text="Buscar" class="btn btn-info"/>

JS:

function btnVisualizar_Click() {
    buscar(); // chama a segunda função
    alert("A função chamada foi 'btnVisualizar_Click'");
}

function buscar() {
    alert("A função chamada foi 'buscar'");
}

Anything, say there that we help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.