Find and click Button in Grid with javascript

2 posts, 0 answers
  1. Fenris
    Fenris avatar
    4 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2015 Link to this post

    Hey,

    I have a Problem with following grid (trimmed down to the essential parts only). On a RadTextBox-Enter I want to call a JavaScript function, which calls the onClick function of  a button with ID "btnSearch". This it how it Looks like

    <script type="text/javascript">
        function OnKeyPress(sender, args)
        {
            if (args.get_keyCode() == 13)
            {
                // find button "btnSearch" and click it
                var buttonTmp = $find("<%= btnSearch.ClientID %>");
                buttomTmp.click();
            }    
        }
    </script>
     
    <telerik:RadGrid runat="server" ID="grid1" GridLines="None" ShowFooter="False" Culture="de-DE">
        <MasterTableView AutoGenerateColumns="False" AllowMultiColumnSorting="True" CommandItemDisplay="Top">
            <CommandItemTemplate>
                <telerik:RadToolBar ID="radToolBar" Skin="Windows7" runat="server" AutoPostBack="true" Width="100%">
                    <Items>
                        <telerik:RadToolBarButton Value="section1"  CssClass="rightAligned">
                            <ItemTemplate>
                                <telerik:RadButton runat="server" Skin="Windows7" Text="ButtonText1" CommandName="ButtonCommand1" OnClick="buttonAction1_Click"/>
                            </ItemTemplate>
                        </telerik:RadToolBarButton>
                        <telerik:RadToolBarButton IsSeparator="True" />
                        <telerik:RadToolBarButton Value="section2">
                            <ItemTemplate>
                                <telerik:RadTextBox ID="textbox1" runat="server" Skin="Windows7"><ClientEvents OnKeyPress="OnKeyPress" /></telerik:RadTextBox>
                                <telerik:RadButton ID="btnSearch" runat="server" Skin="Windows7" Text="Search" CommandName="Search" OnClick="searchButton_Click"/>
                            </ItemTemplate>
                        </telerik:RadToolBarButton>
                    </Items>
                </telerik:RadToolBar>
            </CommandItemTemplate>
        </MasterTableView>
        <GroupingSettings CaseSensitive="False" />
    </telerik:RadGrid>


    Unfortunately, this does not seem to work, since the $find cannot find the button. I also tried to find it like this

    var grid = $find("<%= activePassiveGrid.ClientID %>");
    var MasterTable = grid.get_masterTableView();
    var toolBar = MasterTable.get_dataItems()[0]......

    But I don't get down to the button. Can anyone please lend me some helping hand to find and call my Button?
  2. Fenris
    Fenris avatar
    4 posts
    Member since:
    Feb 2015

    Posted 18 Feb 2015 in reply to Fenris Link to this post

    Maybe it's not very elegant, but I got it working with the help of jQuery.

    function OnKeyPress(sender, args)
    {
        if (args.get_keyCode() == 13)
        {
            var arr_buttons = $("[id$=btnFilter]");
            arr_buttons[0].control.click();
            args.set_cancel(true);
        }    
    }


  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top