Run ASP.NET Events from javascript

0

My problem is that I have a form in ASP.NET in VB and I have events declared in that program, now I need to know how to execute those events from javascript. Visual Event

Protected Sub Cargar()
PanelSearch.Visible = False
End Sub

JavaSCript:

Function CargarDatos(){
document.getElementById("Button1").click();
};

The javascript code works for me but only when the "button1 is visible and as you can see I need to hide it, and when I hide it it does not work anymore. And it has to be that way because I need it to work with javascript. Thanks for your time.

    
asked by Alexis Gonzalez 17.11.2018 в 20:02
source

1 answer

0

When you want to get the ASP tags in Javascript you must use ClientIDs: <%=IDVariable.ClientID%> Example:

ASP

<asp:Button ID="Button1" Runat="server" />

JAVASCRIPT

function CargarDatos(){
    document.getElementById('<%=Button1.ClientID%>').click();
};

Another option to call a Javascript function from an ASP Button is to use the onclientclick method.

<asp:Button ID="Button1" Runat="server" onClientClick="CargarDatos()"/>
    
answered by 18.11.2018 / 07:32
source