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

[Solved] Alternative way to handle [ENTER] key

1 Answer 115 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Massimo Arena
Top achievements
Rank 1
Massimo Arena asked on 21 Dec 2009, 02:22 PM
RadControls for ASP.NET AJAX Q2 2009 SP1 3.5 2008 Visual Basic.NET

Requirements

RadControls version

.NET version

Visual Studio version

programming language

browser support

all browsers supported by RadControls


PROJECT DESCRIPTION
This is an alternative way to handle [ENTER] key to perform insert/update operation inside a RadGrid FormTemplate (EditFormType="Template") within a Content Page (Master Page template). For unknown reason (probably the FormTemplate with customized insert/update and cancel button), I was unable to handle the [ENTER] key event so this is a possible solution:

 <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"
        <script type="text/javascript" language="javascript"
            function onKeyPress(sender, eventArgs) { 
                // 13 is the keycode for enter key 
                if (eventArgs.get_keyCode() == 13) { 
                    // LblUpdateButtonId it's an hidden label that contain the id of my custom insert/update button 
                    var temp = document.getElementById("<%=LblUpdateButtonId.ClientID %>"); 
                    var button_id = temp.innerHTML.replace(/_/g, "$"); 
                    // perform postback 
                    WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(button_id, "", true, "", "", false, true)); 
                    // inhibit event bubbling 
                    eventArgs.set_cancel(true); 
                } 
            } 
    </script> 
    </telerik:RadCodeBlock> 

The custom insert/update asp:button calls a sub on OnLoad event (OnLoad="SetUpdateButtonId") to store his client id in the hidden label because I was unable to retrieve it in a different way:

Protected Sub SetUpdateButtonId(ByVal sender As Object, ByVal e As System.EventArgs) 
      LblUpdateButtonId.Text = CType(sender, Button).ClientID 
End Sub 


1 Answer, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 22 Dec 2009, 03:20 PM
Hi Massimo,

Thank you for sharing your experience with the community. I am sure your solution will help other users as well.

Greetings,
Iana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Massimo Arena
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Share this question
or