Multiple Default Buttons in a User Control

I have a user control consisting of 3 text fields, 3 buttons and a grid. I can set the defaultbutton property of the form, but this will affect only one button.

Each combination of text fields / buttons should have a behavior that, when the text field has focus, pressing the "On" key should launch a button associated with it.

To further complicate the issue, this is used inside the homepage implementation.

Is there any way to do this? As far as I can tell, .NET will only allow one button by default - it does not explicitly associate text fields and buttons.

I welcome your ideas.

+3
source share
3 answers

Here is 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>
+4
source

Try creating a separate user control for each TextBox / Button set. Thus, each text field will launch a button associated with it.

0
source

You can disable the default button and process the text field on the KeyPress event.

0
source

Source: https://habr.com/ru/post/1728058/


All Articles