Shahin
Shahin

Reputation: 12861

Trigger Click event using jQuery

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 ?

Upvotes: 2

Views: 7230

Answers (3)

Govind Malviya
Govind Malviya

Reputation: 13763

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;
             });

            }

Upvotes: 1

Amit
Amit

Reputation: 22086

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

Upvotes: 2

Ahmed Atia
Ahmed Atia

Reputation: 17980

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

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

Upvotes: 2

Related Questions