jQuery trigger click on aspx page is not working

669 views Asked by At

my ASPX Markup is as below

<a id="lnkLogin" href="javascript:__doPostBack('ctl00$LoginReg1$lnkLogin','')">Login</a>

And my function is as below

function LogOut() {
        $("#lnkLogin").trigger('click');
    }

for some reason this trigger click is not working?

I have also tried to do this from code behind like this

If Request.UrlReferrer IsNot Nothing AndAlso Request.UrlReferrer.AbsoluteUri.Contains("32088") Then

        ' Define the name and type of the client script on the page. 
        Dim csName As [String] = "ButtonClickScript"
        Dim csType As Type = Me.[GetType]()

        ' Get a ClientScriptManager reference from the Page class. 
        Dim cs As ClientScriptManager = Page.ClientScript

        ' Check to see if the client script is already registered. 
        If Not cs.IsClientScriptBlockRegistered(csType, csName) Then
            Dim csText As New StringBuilder()
            csText.Append("<script type=""text/javascript""> function LogOut() {")
            csText.Append("$('#lnkLogin').trigger('click');} </")
            csText.Append("script>")
            cs.RegisterClientScriptBlock(csType, csName, csText.ToString())
        End If
    End If

but not use

1

There are 1 answers

3
ShankarSangoli On

Try this

function LogOut() {
    $("#lnkLogin")[0].click();
}