Raymond
Raymond

Reputation: 3

Triggerring an event when Enter is pressed

Is there a way to trigger the update event of listview if the user triggered edit event of listview and if the user is not currently editing the listview, pressing the Enter button will trigger the click event of a certain button.

aspx

   <form runat="server">
    <div class="row">
        <div class="form-group">
            <label class="col-md-3 control-label">Label:</label>
            <div class="col-md-8">
                <asp:TextBox ID="TextBox1" runat="server" />
            </div>
        </div>
    </div>
    <div class="row">
        <table class="table table-bordered table-hover table-responsive">
            <thead>
                <tr>
                    <th>Product ID</th>
                    <th>Product Name</th>
                    <th>Quantity</th>
                    <th></th>
                </tr>    
            </thead>
            <tbody>
                <asp:ListView ID="ListView1" runat="server"
                    onitemcanceling="ListView1_ItemCanceling" 
                    onitemediting="ListView1_ItemEditing" 
                    onitemupdating="ListView1_ItemUpdating" >
                    <ItemTemplate>
                        <tr>
                            <td><%# Eval("ProductID") %></td>
                            <td><%# Eval("ProductName") %></td>
                            <td><%# Eval("Quantity") %></td>
                            <td>
                                <asp:LinkButton ID="lnkDelete" runat="server" 
                                class="glyphicon glyphicon-remove" CommandName="Delete" />
                            </td>
                        </tr>
                    </ItemTemplate>
                    <EmptyDataTemplate>
                        <tr>
                            <td colspan="4"><h5><center>Select a product first then click "Add Product".</center></h5></td>
                        </tr>
                    </EmptyDataTemplate>
                </asp:ListView>
            </tbody>
        </table>
    </div>
    <div class="row">
        <asp:Button ID="button1" runat="server" />

Upvotes: 0

Views: 60

Answers (1)

Rachit Patel
Rachit Patel

Reputation: 862

Use asp:Panel control DefaultButton property to set default button click event

 <asp:Panel ID="pnlMain" runat="server" DefaultButton="btnSend" Width="500px">
 .
 .
 .
   <asp:Button ID="btnSend" runat="server" Text="Save" CssClass="button" OnClick="btnSend_Click" />

 </asp:Panel>

Upvotes: 1

Related Questions