2

I want to trigger an ASP.NET button using jQuery
Target button placed in an Updatepanel
jQuery Code :

    $(document).ready(function () {
     $('.ViewDetail').click(function (e) {
        var ID = $(this).parent().parent().attr('ExpID');
        $("#hflIdentityID").val(ID);
        $("#btnLoadBills").trigger('click');
        $("#ExpenseBills").dialog("open");
        return false;
    });
        });

Mark Up code :

<asp:UpdatePanel ID="DetailBillUpdatepanel" runat="server">
            <ContentTemplate>
                <div id="btnLoadGrid" style="display: none;">
                    <asp:Button ID="btnLoadBills" ClientIDMode="Static" CausesValidation="false" runat="server"
                        Text="Button" />
                </div>
               GridView is Here...
            </ContentTemplate>
        </asp:UpdatePanel>

Behind Code :

Protected Sub btnLoadBills_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLoadBills.Click
        grvExpenseBills.DataSource = tadok.Data.DataRepository.EdlBlpProvider.GetByEdlId(hflIdentityID.Value)
        grvExpenseBills.DataBind()
       End Sub

Why event does not fire ?

1

3 Answers 3

2

put your jquery event handler binding inside the following function

function pageLoad(sender,args) {

    // binding code here, for example
    $('#button').click(function(e) {
        // do something when the click event is raised
    });

}

pageLoad is executed after every postback, synchronous or asynchronous. pageLoad is a reserved function name in ASP.NET AJAX that is for this purpose. $(document).ready() on the other hand, is executed only once, when the DOM is initially ready/loaded.
This has been taken from this

Sign up to request clarification or add additional context in comments.

1 Comment

It works but something is strange for me , because my selector is not in Updatepanel why should i rebind click event outside Document.Ready ?!
2

#btnLoadBills does not represent the actual ID of button, try to use the following

$('#<%= btnLoadBills.ClientID %>').trigger('click');

5 Comments

But ClientIdMode valued static.
I also tried Dynamic ClientID and $('#<%= btnLoadBills.ClientID %>').trigger('click'); it does not work yet
What is the aim of this "return false;" in your $(document).ready, shall you try without it??
Thanks Ahmed , I did rebind my click event after postback regards Thomas answer and it works right now.
I'm not pretty sure of this, but shall you try to add btnLoadBills as a trigger of updatepanel (either synchronous or asynchronous trigger), and try just for try. Also, I hope if you can check button functionality itself apart from trigger/click functions just to check this there is no something in the middle preventing button functionality.
1

Use this code for that kind of situation

 Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandler);


            function endRequestHandler(sender, args)

            {

                 $('.ViewDetail').click(function (e) {
                 var ID = $(this).parent().parent().attr('ExpID');
                 $("#hflIdentityID").val(ID);
                 $("#btnLoadBills").trigger('click');
                 $("#ExpenseBills").dialog("open");
                 return false;
             });

            }

Comments

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.