-1

I've a Link button on a web page which is a child page of a master page. Here is the link button code

<asp:LinkButton ID="lb_submit"  ClientIDMode="Static" runat="server" 
CssClass="btn btn-green submit-button pull-right btn-block">
<span class="start-text" style="font-family:Arial;font-size:14pt;">Start</span>
</asp:LinkButton>

The way I tried to do was

$('#lb_submit').click();

But its not firing the actual click event of that link button.

Also I tried

$('#lb_submit').trigger('click');

That also didnt help me to solve that issue. Actually my purpose was to trigger that button when ever the enter key on anywhere of the page. That event is working fine and I confirmed it. But am sharing that function also

$(document).on("keypress", function (e) {

            if (e.keyCode == 13) {

                // Cancel the default action on keypress event
                e.preventDefault();

                $('#lb_submit').click();
            }
        });

Im not getting an idea what I did wrong

<div class="col-md-2 "><a href="javascript:WebForm_DoPostBackWithOptions
(new WebForm_PostBackOptions(&quot;ctl00$cp_body$lb_submit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))" 
class="btn btn-green submit-button pull-right btn-block" id="lb_submit">
<span style="font-family:Arial;font-size:14pt;" class="start-text">Start</span></a>
</div>
15
  • 1
    What does the client-side markup for the link look like? When you debug this in the browser, does $('#lb_submit') find the element? Commented Oct 1, 2014 at 13:04
  • What version of jQuery are you using? Commented Oct 1, 2014 at 13:06
  • i think you can handle this click event on the server side too. Generate a function on your code behind and write the logic there rather stressing over jQuery . Commented Oct 1, 2014 at 13:06
  • Has the document finished loading before click is called Commented Oct 1, 2014 at 13:13
  • 1
    @sforsandeep: That's a good step toward debugging, but can you share some of that debugging information in the question? Perhaps specify exactly where/how the code is behaving differently from what is expected? Currently this exchange is very close to saying, "Trust me, I confirmed that my code is fine so you don't need to see it. But can you tell me why it doesn't work?" Which is inherently unanswerable. I'm not trying to sound rude, and I hope it's not coming across that way in this text-only medium. It just seems that some more debugging information is required to solve the issue. Commented Oct 1, 2014 at 13:35

2 Answers 2

0

Try this code:

$(document).keyup(function(event){
    if(event.keyCode == 13){
        $("#lb_submit").click();
    }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Actually the enter key part is working perfect. The code which is not working is triggering the submit button click event. I tried an alert before that click trigger which worked fine.. So its not with the fault of Enter key handler
0

Perhaps the actual ID of the control as rendered by the web server is different, something like ctl00_lb_submit. Try this:

$('<%= this.lb_submit.ClientID %>').click();

1 Comment

No it wont be since I specified ClientIDmode as static. So even in client side the ID will be same as server side

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.