Invoke OnClick event from an asp: LinkButton from JavaScript?

0

I need to invoke the session closing method from JavaScript (once the system counter reaches 0). Sight code:

<asp:LinkButton 
    ID="Lbtn_Salir" 
    type="button" 
    runat="server" 
    OnClick="Lbtn_Salir_Click" 
    OnClientClick="Lbtn_Salir_Click">
    Salir
</asp:LinkButton>

The code associated with that view:

public void os(string value, object target)
{
    Session[value] = target;
}

protected void Lbtn_Salir_Click(object sender, EventArgs e)
{            
    os("ID_USER", null);
    os("MENU", null);
    Response.Redirect("~/Login.aspx", false);
}

When the button is pressed by the user, the session variables are destroyed correctly and the application sends it to the home page. What I want is to reuse that function from a script, however nothing happens once I invoke the click event associated with the Exit button.

function salir(){
    // Reloj llega a 0

    // Método 1
    var btn_salir = $("#Lbtn_Salir");
    btn_salir.click();

    // Método 2
    $('#btn_salir').trigger('click');
}
    
asked by alexander zevallos 21.06.2016 в 18:56
source

2 answers

1

One option could be:

function salir() {
    __doPostBack('Lbtn_Salir', '');
}

And in your .cs, in the Page_Load:

if (Request.Form["__EVENTTARGET"] == "Lbtn_Salir")
{    
    Lbtn_Salir_Click(this, new EventArgs());    
}

And execute the function exit where you want.

    
answered by 21.06.2016 / 19:19
source
0

Your problem is in the script, you should remove the function and put:

$(document).ready(function(){
    // Reloj llega a 0

    // Método 1
    var btn_salir = $("#Lbtn_Salir");
    btn_salir.click();

    // Método 2
    $('#btn_salir').trigger('click');
});

This way you can read the function of the onclick button.

    
answered by 21.06.2016 в 19:12