Search code examples
jquerydevexpressaspx-user-control

How to use jQuery to cause ASPxButton to click?


I have an ASPxButton:

<dx:aspxbutton ID="btnRefreshData" runat="server" Text="Refresh" 
                    meta:resourcekey="btnRefreshDataResource1">
                </dx:aspxbutton>

I have use jQuery to cause a click on the button:

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

But thing doesn't work out. The button doesn't click. Could you help me to find a solution on this?


Solution

  • Actually, DevExpress has provided a lot of JavaScript functions to help us to do this:

    aspxBClick("MainContent_btnRefreshData")
    

    "MainContain" is the ID of Content Place Holder. The button must stay inside the content place holder to get this effected. To archive this, we call "aspxBClick" function and pass a parameter which is a string compiled of Content place holder ID and the Button's ID.

    Example Code:

    <script>
    aspxBClick("MainContent_btnRefreshData")
    </script>
    
    <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
        <dx:aspxbutton ID="btnRefreshData" runat="server" Text="Refresh" 
                        meta:resourcekey="btnRefreshDataResource1">
                    </dx:aspxbutton>
        </asp:Content>
    

    Additional way:

    We can call button id to do click:

    btnRefreshData.DoClick();
    

    Remember to add attribute ClientInstanceName to the button:

    <dx:aspxbutton ID="btnRefreshData" runat="server" Text="Refresh" ClientInstanceName="btnRefreshData"
                        meta:resourcekey="btnRefreshDataResource1">
                    </dx:aspxbutton>
        </asp:Content>