Take the community feedback survey now.
                AI OnAI Off
            
        Take the community feedback survey now.
 
                
// Created by Janus Kamp Hansen - http://www.kamp-hansen.dk
// Ported to C# by Steve Celius
// Modified to suit XForm webcontrols by Bjørn Gustafson
public static void SetDefaultButton(System.Web.UI.Page page, EPiServer.XForms.WebControls.Input textBox, EPiServer.XForms.WebControls.Submit defaultButton )
{
	//System.Text.StringBuilder sScript = new System.Text.StringBuilder();
	string ClickButtonWithNameScript = @"
";
	string FindButtonWithNameScript = @"
";
	string buttonname = defaultButton.ClientID;
	buttonname = buttonname.Replace("_",":");
	buttonname = buttonname.Replace("::",":_");
	textBox.Attributes.Add("onkeydown", "ClickButtonWithName('" + buttonname + "')");
	page.RegisterStartupScript("ClickButtonWithNameScript", ClickButtonWithNameScript);
	page.RegisterStartupScript("FindButtonWithNameScript", FindButtonWithNameScript);
}
Your ControlsCreated function could look something like this:
private void FormControl_ControlsCreated(object sender, EventArgs e)
{
	// Find the submit button, if any
	System.Web.UI.Control submitbutton = null;
	foreach (System.Web.UI.Control formcontrol in FormControl.Controls)
		if (formcontrol is EPiServer.XForms.WebControls.Submit)
			submitbutton = formcontrol;
	// Loop through all the xform controls
	foreach (System.Web.UI.Control formcontrol in FormControl.Controls)
	{
		// We are dealing with an input field (textbox) and the form has a submit button
		if ((submitbutton != null) && (formcontrol is EPiServer.XForms.WebControls.Input))
		{
			// Set the button as the default button when hitting enter in a field
			SetDefaultButton(Page,(EPiServer.XForms.WebControls.Input)formcontrol,(EPiServer.XForms.WebControls.Submit)submitbutton);
		}
	}
}
Hope this can come in handy for someone, and don't hesitate to let me know if you have suggestions for improvement to the code or a simpler workaround than the one presented here! :-)
-b
                        