What do i add to code be able to hit enter as well as clicking the button.

<%@ Page Language="VB" %>
<script runat="server">
    Function era(ByVal yEAR As Integer) As System.Data.DataSet
            Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=Cresta Tunes.mdb"
            Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString)

            Dim queryString As String = "SELECT [Cresta Tunes].[ARTIST], [Cresta Tunes].[TITLE], [C"& _
    "resta Tunes].[MP3_D], [Cresta Tunes].[MP3_T], [Cresta Tunes].[CD_D], [Cresta Tun"& _
    "es].[CD_T], [Cresta Tunes].[YEAR],[Cresta Tunes].[CATEGORY] FROM [Cresta Tunes] WHERE ([Cresta Tunes]."& _
    "[YEAR] LIKE '%' &  @YEAR & '%')"
            Dim dbCommand As System.Data.IDbCommand = New System.Data.OleDb.OleDbCommand
            dbCommand.CommandText = queryString
            dbCommand.Connection = dbConnection

            Dim dbParam_yEAR As System.Data.IDataParameter = New System.Data.OleDb.OleDbParameter
            dbParam_yEAR.ParameterName = "@YEAR"
            dbParam_yEAR.Value = yEAR
            dbParam_yEAR.DbType = System.Data.DbType.Int32
            dbCommand.Parameters.Add(dbParam_yEAR)

            Dim dataAdapter As System.Data.IDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter
            dataAdapter.SelectCommand = dbCommand
            Dim dataSet As System.Data.DataSet = New System.Data.DataSet
            dataAdapter.Fill(dataSet)

            Return dataSet
        End Function' Insert page code here
    '

    Sub Button2_Click(sender As Object, e As EventArgs)
    Datagrid2.DataSource = era(TextBox2.Text)
    DataGrid2.DataBind()
    End Sub

    Sub LinkButton1_Click(sender As Object, e As EventArgs)

    End Sub

    Sub TextBox2_TextChanged(sender As Object, e As EventArgs)
    TextBox2.Attributes.Add("onkeydown", "if(event.which event.keyCode){if ((event.which == 13) (event.keyCode == 13)) {document.getElementById('"+Button2.UniqueID+"').click();return false;}} else {return true}; ");
    End Sub
</script>
<html xmlns:o= "urn:schemas-microsoft-com:office:office">
<head>
</head>
<body>
    <form runat="server">
        <p>
        </p>
        <p align="center">
            <strong><u><font size="6">Search by Year</font></u></strong> 
        </p>
        <p>
        </p>
        <p>
            <table class="MsoTableGrid" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; MARGIN-LEFT: 71.1pt; BORDER-LEFT: medium none; BORDER-BOTTOM: medium none; BORDER-COLLAPSE: collapse; mso-border-alt: solid windowtext .5pt; mso-yfti-tbllook: 480; mso-padding-alt: 0cm 5.4pt 0cm 5.4pt; mso-border-insideh: .5pt solid windowtext; mso-border-insidev: .5pt solid windowtext" bordercolor="maroon" cellspacing="2" cellpadding="2" rules="cols" align="right" bgcolor="azure" border="1">
                <tbody>
                    <tr style="HEIGHT: 120.1pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes; mso-yfti-lastrow: yes">
                        <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: windowtext 1pt solid; WIDTH: 315pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 120.1pt; mso-border-alt: solid windowtext .5pt" valign="top" width="420">
                            <p style="TEXT-ALIGN: center" align="center">
                                <u><span style="FONT-SIZE: 24pt; COLOR: black"><a href="Artist Search.aspx"><font color="blue"><font size="3">Search
                                by</font> <font size="3">Artist</font></font></a></span></u><font color="blue" size="5"> </font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <u><span style="FONT-SIZE: 24pt; COLOR: black"><a href="Title Search.aspx"><font color="blue" size="3">Search
                                by </font></a></span></u><font size="3"><u><span style="FONT-SIZE: 24pt; COLOR: black"><font color="blue">Title</font></span></u><font color="blue"> </font></font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <u><span style="FONT-SIZE: 24pt; COLOR: black"><a href="Cresta Tunes.aspx"><font color="blue"><font size="3">Search
                                by</font> <font size="3">Artist &amp; Title</font></font></a></span></u> 
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <font size="6"><a href="Year Search.aspx"><font color="blue"><font size="3">Search
                                by</font> <font size="3">Year</font></font></a></font><font color="blue"> </font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <font size="6"><a href="Category Search.aspx"><font color="blue"><font size="3">Search
                                by</font> <font size="3">Category</font></font></a></font><font color="blue"> </font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <font size="6"><a href="Year &amp; Category Search.aspx"><font color="blue"><font size="3">Search
                                by</font> <font size="3">Year &amp; Category</font></font></a></font><font color="blue" size="5"> </font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <u><a href="<A href="http://localhost:8080/MP3%20Search.aspx"><font">http://localhost:8080/MP3%20Search.aspx"><font color="blue">Search by
                                MP3 Disc</font></a></u><font color="blue"> </font>
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                                <u><a href="<A href="http://localhost:8080/CD%20Search.aspx"><font">http://localhost:8080/CD%20Search.aspx"><font color="blue">Search by CD
                                Disc</font></a></u> 
                            </p>
                            <p style="TEXT-ALIGN: center" align="center">
                            </p>
                        </td>
                        <td style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5.4pt; PADDING-BOTTOM: 0cm; BORDER-LEFT: medium none; WIDTH: 630pt; PADDING-TOP: 0cm; BORDER-BOTTOM: windowtext 1pt solid; HEIGHT: 120.1pt; mso-border-alt: solid windowtext .5pt; mso-border-left-alt: solid windowtext .5pt" valign="top" width="840">
                            <o:p>
                                <strong><font size="4"> 
                                <p>
                                    <strong><u>Year</u>&nbsp;</strong>&nbsp; 
                                    <asp:TextBox id="TextBox2" runat="server" BorderStyle="Solid" BorderColor="Teal" BorderWidth="2px" Columns="1" OnTextChanged="TextBox2_TextChanged"></asp:TextBox>
                                </p>
                                <p>
                                    <asp:Button id="Button2" onclick="Button2_Click" runat="server" BorderColor="Red" Font-Underline="True" ForeColor="Red" Font-Bold="True" Text="Search" BackColor="Yellow"></asp:Button>
                                </p>
                                <p></p>
                                <p>
                                    <asp:DataGrid id="DataGrid2" tabIndex="1" runat="server" BorderColor="Maroon" Font-Bold="True" BackColor="#C0FFFF" PageSize="20" AllowSorting="True" HorizontalAlign="Left" CellSpacing="5" CellPadding="5" Font-Size="Smaller" CaptionAlign="Left" Width="304px">
                                        <SelectedItemStyle backcolor="White"></SelectedItemStyle>
                                        <EditItemStyle backcolor="Transparent"></EditItemStyle>
                                        <AlternatingItemStyle borderwidth="2px" borderstyle="Solid" bordercolor="Black" backcolor="#00C0C0"></AlternatingItemStyle>
                                        <HeaderStyle borderwidth="5px" forecolor="White" borderstyle="Solid" bordercolor="White" backcolor="DarkOrchid"></HeaderStyle>
                                    </asp:DataGrid>
                                </p>
                                <p></p>
                                </font></strong> 
                                <p align="center"></p>
                            </o:p>
                        </td>
                    </tr>
                </tbody>
            </table>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
        </p>
        <!-- Insert content here -->
    </form>
    </BODY></HTML>

Thanks in advance to anyone who can help!!

Member Avatar for iamthwee

You need to write a key listener which listens for the <enter> key and if pressed fires off the click button part.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.