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

Button doesn't work with asp:Panel DefaultButton property nor UseSubmitBehaviour is rendering submit input?

8 Answers 735 Views
Button
This is a migrated thread and some comments may be shown as answers.
Ivan Zlatanov
Top achievements
Rank 1
Ivan Zlatanov asked on 22 Aug 2011, 09:05 AM
Hi,

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]?

Thanks,

Ivan.

8 Answers, 1 is accepted

Sort by
0
Slav
Telerik team
answered on 24 Aug 2011, 01:59 PM
Hello Ivan,

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.

Best wishes,
Slav
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Ivan Zlatanov
Top achievements
Rank 1
answered on 24 Aug 2011, 02:30 PM
Hi,

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:automargin-right:automargin-top20px;">
			<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>


Kind Regards,

Ivan Zlatanov.
0
Accepted
Slav
Telerik team
answered on 26 Aug 2011, 02:39 PM
Hi Ivan,

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.

Regards,
Slav
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Michal
Top achievements
Rank 1
answered on 05 Dec 2013, 03:29 PM
Hi Slav,

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.
0
Danail Vasilev
Telerik team
answered on 10 Dec 2013, 07:37 AM
Hi Michal,

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:
<script type="text/javascript">
    Telerik.Web.UI.RadButton.prototype._isInputTypeText = function (element) {
        var nodeName = element.nodeName, type = element.type;
        if (nodeName != "INPUT" || !type) return false;
        return type == "text" || type == "password" || type == "email" || type == "number" || type == "url" || type == "search" || type == "tel";
    }
</script>


Regards,
Danail Vasilev
Telerik
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 the blog feed now.
0
Chris
Top achievements
Rank 1
answered on 09 Jul 2014, 08:59 PM
Is it possible this issue has returned with Q2 2014? I'm having the exact issue described above where it won't act as the default button when the focus is in a password field. A regular asp:button works fine however a RadButton does not.
0
Danail Vasilev
Telerik team
answered on 14 Jul 2014, 11:36 AM
Hi Chris,

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.

Regards,
Danail Vasilev
Telerik
 

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.

 
0
Chris
Top achievements
Rank 1
answered on 22 Jul 2014, 01:19 PM
Thanks for the workaround Danail!
Tags
Button
Asked by
Ivan Zlatanov
Top achievements
Rank 1
Answers by
Slav
Telerik team
Ivan Zlatanov
Top achievements
Rank 1
Michal
Top achievements
Rank 1
Danail Vasilev
Telerik team
Chris
Top achievements
Rank 1
Share this question
or