This is a migrated thread and some comments may be shown as answers.

Find and click Button in Grid with javascript

1 Answer 738 Views
Button
This is a migrated thread and some comments may be shown as answers.
Fenris
Top achievements
Rank 1
Fenris asked on 18 Feb 2015, 12:41 PM
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?

1 Answer, 1 is accepted

Sort by
0
Fenris
Top achievements
Rank 1
answered on 18 Feb 2015, 01:03 PM
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);
    }    
}


Tags
Button
Asked by
Fenris
Top achievements
Rank 1
Answers by
Fenris
Top achievements
Rank 1
Share this question
or