RadControls for ASP.NET AJAX Q2 2009 SP1 3.5 2008 Visual Basic.NET
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:
| 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 |