I am trying to achieve a post back on enter key pressed. I found out that the RadButton's property UseSubmitBehaviour doesn't do anything? I would expect if this is true, the button to be actually a submit button and if false to be a normal button. This seems not to be true here.
As I found out this is not working out, I tried using asp.net control Panel and it's property - DefaultButton to see if it's going to help, but it didn't.
I am using the latest version of the telerik ajax controls library. How can I achieve autopostback on enter? I don't want to subscribe to keypress events and watch for enter key. This should be built in. How can RadButton render input[type=submit] instead of input[type=button]?
8 Answers, 1 is accepted
Indeed, the UseSubmitBehaviour property of the RadButton should be set to true, so that the button is rendered as input HTML element of type submit, which is set by default. Also, the DefaultButton property of the form can be used to define a button that will trigger the postback, when the Enter key is pressed. Please note that this is a general knowledge and the same effect will be achieved with a standard Button control.
If the scenario, described above, doesn't function properly on your end and the RadButton is rendered as input of type button, my suggestion is to check whether there is a validation controls on your page. Since by default all ASP Buttons (including the RadButton) trigger the page validation, you can exclude some of them by setting their CausesValidation property to false.
You can find a sample project, implementing the described scenario. Please use it as a reference to incorporate this functionality in your actual project.
the Telerik team
Your code works, but mine still doesn't and I think I found out which is causing it.
My page has a password field with a required field validator, if I remove it then it works, if it's there, it doesn't. Can you tell me why is this happening? Here is my code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultButton.aspx.cs" Inherits="DefaultButton" %> <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager runat="server" /> <table border="0" style="margin-left:auto; margin-right:auto; margin-top: 20px;"> <tr> <td class="Label">Username:</td> <td> <asp:TextBox ID="Nickname" ClientIDMode="Static" runat="server" Width="160px" /> <asp:RequiredFieldValidator Font-Bold="true" runat="server" ControlToValidate="Nickname" ErrorMessage="*" /> </td> </tr> <tr> <td class="Label">Password:</td> <td> <asp:TextBox ID="Password" TextMode="Password" runat="server" Width="160px" /> <asp:RequiredFieldValidator Font-Bold="true" runat="server" ControlToValidate="Password" ErrorMessage="*" /> </td> </tr> <tr> <td></td> <td align="left"> <br /> <telerik:RadButton ClientIDMode="Static" ID="loginButton" Text="Logon" runat="server" Width="100px" /> </td> </tr> </table> </form> </body> </html>
As I suspected, you have validation controls on your page, more specifically RequiredFieldValidators. By default, when a RadButton is placed on a page with validation controls, its default action is to trigger validation, when pressed. If the conditions, specified by the validation controls, are not met, the RadButton will be rendered as a HTML input element of type button and the postback will not be initiated. In your case you have empty fields on the page and the RequiredFieldValidators, attached to them, are preventing postback.
The solution, in case you want to exclude the RadButton from the validation mechanism, is to set the button's CausesValidation property to false. This way you will ensure that the RadButton will always cause postback. Please note that in such case the users will be able to post the page without entering credentials.
I would like to bring to your attention one more issue of concern. It seems that you have specified ClientIDMode="Static" for the RadButton. It is recommends by Microsoft to use ClientIDMode set to Static only for static controls.The RadControls on the other hand are controls with complex hierarchies of child controls and templates so setting their ClientIDMode property to Static may break their functionality. What I would recommend is that you do not use ClientIdMode Static for any Telerik controls. You can also check the following thread explaining this behavior: http://www.telerik.com/community/forums/aspnet-ajax/general-discussions/clientidmode-support-for-asp-net-4-0.aspx.
the Telerik team
Solution does not work when the property TextMode of asp:TextBox is set to "Password". When I press enter on that textbox, nothing happens. If this property is not set, pressing enter on this textbox cause a postback and everything works as it should.
In Q3 2013 there is an issue with the clicking of the RadButton when Enter keys is pressed inside password TextBox. The issue is logged in our feedback portal here and is already fixed in Q3 2013 SP1.
What I can suggest is that you:
- either upgrade your version of RadControls to Q3 2013 SP1
- OR put the following workaround either below the declaration of the RadButton or at the end of the MasterPage:
In Q2 2014 RadButton is not performing PostBacks when triggers validation and is set as DefaultButton. The issue has already been logged here and will be fixed for the upcoming Q2 2014 SP1, scheduled for the end of this month.
For the time being you can set RadButton's UseSubmitBehavior property to False.
Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.