Bill Barry
Bill Barry

Reputation: 3543

Setting the default submit button without an asp:panel

I have a page with user controls getting dynamically added. Inside some of these user controls there are form elements, either simple <input> tags or complex third party controls (Telerik RadDatePicker for example) (technical details at end).

These controls are currently being identified as part of the same form based on a ValidationGroup string setting. My question is how can I get these form elements to submit on Enter together and raise the right postback event?

I cannot use the DefaultButton panel property because I don't have the id of the submit button available within the controls server-side. I think I might be able to use jquery clientside like this:
<input onKeyPress="javascript:if (event.keyCode == 13) {$(this).change(); $('#submitclientid').click();}" ...>

But I don't know how to do that for the third party controls.

Further technical details:
Each form element is in a separate DNN module. Inter-module communication can be used to pass around data server side which results in multiple modules working together as part of a single logical form on a page.

Upvotes: 2

Views: 1252

Answers (3)

MCurbelo
MCurbelo

Reputation: 4143

By code.

aspx: 1 form (form1), 2 buttons (Button1 & Button2)

aspx.cs:

protected void Page_Load(object sender, System.EventArgs e)
{
   form1.DefaultButton = Form.FindControl("Button2").UniqueID;
}

Upvotes: 0

Richard
Richard

Reputation: 1252

Have you tried setting the DefaultButton property of Form?

Example:

<form defaultButton="myButtonControl" runat="server">
...
</form>

Upvotes: 0

Bill Barry
Bill Barry

Reputation: 3543

Apparently the only way to do this is via client side JS as suggested in the question (you can however skip the jquery and instead use __dopostback).

Upvotes: 1

Related Questions