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

RadGrid Enter press firing ItemCommand

3 Answers 197 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 06 Jan 2012, 01:40 PM
Hi,
I currently have two issues.  My first issue is that, when  I press enter in the RadGrid filter box it fires the ItemCommand event with an CommandArgument that is set to another button. The other button shows and hides the filter row.So when pressing enter it seems to hide the filter row rather than just applying the filter.  This only seems to be the case in IE, in chrome it works as expected.  I was trying to produce a sample for this issue but unfortunately I hit another issue i couldn't solve in my sample.

Issue 2 (sample issue)
In my sample, When i press enter in the box the page reloads but it doesnt filter the items.  When I refocus the filter box and press enter it then filters successfully.  I also noticed that the filter drop down was not displaying.  Once again, this all works fine in chrome but not in Internet Explorer.

Here is the sample which currently has issue 2. I am hoping that if we can resolve issue 2 it will then display the problems I was having with issue 1 and you can help me solve this as well. 


http://dl.dropbox.com/u/13207221/TelerikRadGridTest.zip

3 Answers, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 1
answered on 09 Jan 2012, 11:47 AM
Bump. Any ideas on this?

Thanks,
Michael
0
Accepted
Pavlina
Telerik team
answered on 09 Jan 2012, 05:15 PM
Hello,

Indeed your first issue can be observed in such scenarios, because when enter button is clicked the focus moves over the first button on the page. Therefore to overcome it you can add additional button on the page with display:none as shown below:
<asp:Button ID="DefaultButton1" runat="server" Style="display: none" />

and then set it as defaultbutton of the page form:
<form id="Form1" runat="server" defaultbutton="DefaultButton1">

Regarding your second problem - after you press enter key, JavaScript error is fired(Unspecified error), therefore the items are not filtered. Note that to see the error you should enable Script debugging.

However, to filter items on enter key press you should wired the onkeydown event:
Public Sub dbGrid_ItemDataBound(ByVal o As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles dbGrid.ItemDataBound
      If TypeOf (e.Item) Is GridFilteringItem Then
          Dim item As GridFilteringItem = e.Item
          Dim filter1 As TextBox = item("Name").Controls(0)
          filter1.Attributes.Add("onchange", "javascript:return false;")
          filter1.Attributes.Add("onkeydown", "doFilter(this,event)")
      End If
  End Sub

and execute the JavaScript function below:
function doFilter(sender, eventArgs) {
           if (eventArgs.keyCode == 13) {
               eventArgs.cancelBubble = true;
               eventArgs.returnValue = false;
               if (eventArgs.stopPropagation) {
                   eventArgs.stopPropagation();
                   eventArgs.preventDefault();
               }
               var masterTableView = $find("<%= dbGrid.ClientID %>").get_masterTableView();
               masterTableView.filter("Name", sender.value, Telerik.Web.UI.GridFilterFunction.Contains);
 
           }

Additionally, i am sending you a modified application that is working properly. Examine it and let me know if any problems arise.

All the best,
Pavlina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Michael
Top achievements
Rank 1
answered on 09 Jan 2012, 06:15 PM
Hi,
Thanks very much for this. It is now working as expected.

Regards,
Michael
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Michael
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or