In the page below I have multiple buttons along with two textboxes and two search buttons. What I want to do is give the user the ability to press Enter in either textbox and then to process information according to which textbox received the Enter key command.
Right now if the user types text in either textbox and presses enter the first button on the form is "clicked". Is there a way to do this in ASP.NET? I looked for an OnKeyPressed event in the textbox but there is not one.
Any ideas?
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Main.aspx.vb" Inherits="Payroll_Application.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="False" name="vs_showGrid">
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
<!--#include file="PayAppHeader.aspx" -->
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table borderColor="darkblue" cellSpacing="0" cellPadding="5" bgColor="lemonchiffon" border="1">
<tr>
<td align="middle" bgColor="darkblue"><asp:label id="lblTasks" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">TASKS</asp:label></td>
<td align="middle" bgColor="darkblue"><asp:label id="Label2" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">REPORTS</asp:label></td>
</tr>
<tr>
<td>
<table>
<tr>
<td style="WIDTH: 17px"><font size="-1"><i><asp:button id="Button2" runat="server" Height="21px" Width="88px" Font-Size="XX-Small" Text="New Record" Font-Italic="True"></asp:button></i></font></td>
<TD><asp:button id="Button5" runat="server" Height="21px" Width="104px" Font-Size="XX-Small" Text="Alternate Payment" Font-Italic="True"></asp:button></TD>
<TD><font size="-1"><i><asp:button id="Button1" runat="server" Height="21px" Width="88px" Font-Size="Smaller" Text="Upload Abra" Font-Italic="True"></asp:button></i></font></TD>
</tr>
</table>
</td>
<td>
<table cellPadding="5" border="0">
<tr>
<TD style="WIDTH: 80px"><asp:button id="Button4" runat="server" Height="21px" Font-Size="XX-Small" Text="New Record Report" Font-Italic="True"></asp:button></TD>
<td><font size="-1"><i><asp:button id="Button3" runat="server" Height="21px" Font-Size="Smaller" Text="401K Report" Font-Italic="True"></asp:button></i></font></td>
<TD><font size="-1"><i><asp:button id="Button6" runat="server" Height="21px" Font-Size="Smaller" Text="4th Thursday Report" Font-Italic="True"></asp:button></i></font></TD>
</tr>
</table>
</td>
</tr>
<tr>
<td align="middle" bgColor="darkblue"><asp:label id="Label3" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">QUICK LOOKUP</asp:label></td>
<td align="middle" bgColor="darkblue"><asp:label id="Label5" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">SEARCH</asp:label></td>
</tr>
<tr>
<TD>ID #:<asp:textbox id="txtIDNbr" Runat="server"></asp:textbox><asp:button id="btnTrialBal" runat="server" Height="21px" Font-Size="XX-Small" Text="Quick Lookup" Font-Italic="True"></asp:button></TD>
<td>
<table cellPadding="10">
<tr>
<td>Find records where
<asp:dropdownlist id="ddlField" Runat="server"></asp:dropdownlist></td>
<td><asp:dropdownlist id="ddlQualifier" Runat="server"></asp:dropdownlist></td>
<td><asp:textbox id="txtSearchVal" Runat="server"></asp:textbox></td>
<td><asp:button id="Button8" Font-Size="XX-Small" Text="Search" Runat="server"></asp:button></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
<asp:datagrid id="DataGrid1" runat="server" Font-Size="10pt" AlternatingItemStyle-BackColor="#ffffcc" autogeneratecolumns="False" DataKeyField="IDNbr" OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" AllowPaging="True" PageSize="15">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="IDNbr" DataNavigateUrlFormatString="Roundhouse.aspx?IDNbr={0}" DataTextField="IDNbr" HeaderText="ID #" NavigateUrl="Roundhouse.aspx">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="EmplID" HeaderText="Empl ID">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" Width="100px" BackColor="DarkBlue"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Empl Name">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" Width="100px" BackColor="DarkBlue"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Debt Type
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDebtType" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DebtType" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditDebtType" Runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Payee ID
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PayeeID" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlPayeeID" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="LookupPayee"></aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Payee
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayee" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Payee" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditPayee" Runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn HeaderStyle-BackColor="darkblue" ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn HeaderStyle-BackColor="darkblue" Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" Mode="NumericPages"></PagerStyle>
</asp:datagrid><br>
</form>
</body>
</HTML>
Right now if the user types text in either textbox and presses enter the first button on the form is "clicked". Is there a way to do this in ASP.NET? I looked for an OnKeyPressed event in the textbox but there is not one.
Any ideas?
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="Main.aspx.vb" Inherits="Payroll_Application.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="False" name="vs_showGrid">
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content=" name="vs_targetSchema">
<!--#include file="PayAppHeader.aspx" -->
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table borderColor="darkblue" cellSpacing="0" cellPadding="5" bgColor="lemonchiffon" border="1">
<tr>
<td align="middle" bgColor="darkblue"><asp:label id="lblTasks" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">TASKS</asp:label></td>
<td align="middle" bgColor="darkblue"><asp:label id="Label2" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">REPORTS</asp:label></td>
</tr>
<tr>
<td>
<table>
<tr>
<td style="WIDTH: 17px"><font size="-1"><i><asp:button id="Button2" runat="server" Height="21px" Width="88px" Font-Size="XX-Small" Text="New Record" Font-Italic="True"></asp:button></i></font></td>
<TD><asp:button id="Button5" runat="server" Height="21px" Width="104px" Font-Size="XX-Small" Text="Alternate Payment" Font-Italic="True"></asp:button></TD>
<TD><font size="-1"><i><asp:button id="Button1" runat="server" Height="21px" Width="88px" Font-Size="Smaller" Text="Upload Abra" Font-Italic="True"></asp:button></i></font></TD>
</tr>
</table>
</td>
<td>
<table cellPadding="5" border="0">
<tr>
<TD style="WIDTH: 80px"><asp:button id="Button4" runat="server" Height="21px" Font-Size="XX-Small" Text="New Record Report" Font-Italic="True"></asp:button></TD>
<td><font size="-1"><i><asp:button id="Button3" runat="server" Height="21px" Font-Size="Smaller" Text="401K Report" Font-Italic="True"></asp:button></i></font></td>
<TD><font size="-1"><i><asp:button id="Button6" runat="server" Height="21px" Font-Size="Smaller" Text="4th Thursday Report" Font-Italic="True"></asp:button></i></font></TD>
</tr>
</table>
</td>
</tr>
<tr>
<td align="middle" bgColor="darkblue"><asp:label id="Label3" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">QUICK LOOKUP</asp:label></td>
<td align="middle" bgColor="darkblue"><asp:label id="Label5" Font-Italic="True" Runat="server" Font-Bold="True" ForeColor="yellow">SEARCH</asp:label></td>
</tr>
<tr>
<TD>ID #:<asp:textbox id="txtIDNbr" Runat="server"></asp:textbox><asp:button id="btnTrialBal" runat="server" Height="21px" Font-Size="XX-Small" Text="Quick Lookup" Font-Italic="True"></asp:button></TD>
<td>
<table cellPadding="10">
<tr>
<td>Find records where
<asp:dropdownlist id="ddlField" Runat="server"></asp:dropdownlist></td>
<td><asp:dropdownlist id="ddlQualifier" Runat="server"></asp:dropdownlist></td>
<td><asp:textbox id="txtSearchVal" Runat="server"></asp:textbox></td>
<td><asp:button id="Button8" Font-Size="XX-Small" Text="Search" Runat="server"></asp:button></td>
</tr>
</table>
</td>
</tr>
</table>
<br>
<br>
<asp:datagrid id="DataGrid1" runat="server" Font-Size="10pt" AlternatingItemStyle-BackColor="#ffffcc" autogeneratecolumns="False" DataKeyField="IDNbr" OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" AllowPaging="True" PageSize="15">
<AlternatingItemStyle BackColor="#FFFFCC"></AlternatingItemStyle>
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="IDNbr" DataNavigateUrlFormatString="Roundhouse.aspx?IDNbr={0}" DataTextField="IDNbr" HeaderText="ID #" NavigateUrl="Roundhouse.aspx">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" BackColor="DarkBlue"></HeaderStyle>
</asp:HyperLinkColumn>
<asp:BoundColumn DataField="EmplID" HeaderText="Empl ID">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" Width="100px" BackColor="DarkBlue"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Empl Name">
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="Yellow" Width="100px" BackColor="DarkBlue"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Debt Type
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDebtType" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DebtType" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditDebtType" Runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Payee ID
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="Label1" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PayeeID" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlPayeeID" Runat="server" AutoPostBack="True" OnSelectedIndexChanged="LookupPayee"></aspropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderStyle-BackColor="DarkBlue" HeaderStyle-ForeColor="Yellow" HeaderStyle-Font-Bold="True">
<HeaderTemplate>
Payee
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblPayee" Runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Payee" %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblEditPayee" Runat="server"></asp:Label>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn HeaderStyle-BackColor="darkblue" ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn HeaderStyle-BackColor="darkblue" Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" Mode="NumericPages"></PagerStyle>
</asp:datagrid><br>
</form>
</body>
</HTML>