views:

205

answers:

3

I have a user control that is comprised of 3 textboxes, 3 buttons and a gridview. I can set the defaultbutton property of the form, but that would only affect one button.

Each textbox/button combo should have a behavior that when the textbox has focus, pressing Enter should fire its associated button.

To further complicate the issue, this is being used inside a Master Page implementation.

Is there any way to do this? As far as I can tell, .NET will only allow one default button - it doesn't provide to explicitly associate textboxes and buttons.

I welcome your insights.

A: 

Try creating a separate User Control for each TextBox/Button set. That way each Textbox will fire it's associated Button.

jinsungy
I see what you mean, but to me that overcomplicates the page. I might as well just have the users just click the associated button. I have them doing that now anyway.
Al
A: 

You can disable the default button and handle the textbox's onKeyPress event.

David
A: 

Here one way:

<form id="form1" runat="server">
<div>
    <asp:Panel ID="Panel1" DefaultButton="Button1" runat="server">
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </asp:Panel>
    <asp:Panel ID="Panel2" DefaultButton="Button2" runat="server">
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button2" runat="server" Text="Button" />
    </asp:Panel>
    <asp:Panel ID="Panel3" DefaultButton="Button3" runat="server">
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button3" runat="server" Text="Button" />
    </asp:Panel>
</div>
</form>
Saar
That worked perfectly. Thank you. Vielen Dank!
Al
You're welcome.
Saar