I am trying to trigger the btnSearchSuiteGroup_Click
event when the "enter" key is pressed on the txtSuiteGroupName
textbox in the aspx file. Below is the code snippet:
<asp:TextBox ID="txtSuiteGroupName" runat="server" clientidmode="Static" CssClass="DD" onkeypress="return searchKeyPress(event)"></asp:TextBox>
<asp:Button ID="btnSearchSuiteGroup" runat="server" Text="Search" CssClass="DD" Width="64px" onclick="btnSearchSuiteGroup_Click" />
<script type="text/javascript">
function searchKeyPress(e) {
// look for window.event in case event isn't passed in
if (typeof e == 'undefined' && window.event) { e = window.event; }
if (e.keyCode == 13) {
document.getElementById('<%=btnSearchSuiteGroup.ClientID%>').click();
}
}
</script>
The functionality for btnSearchSuiteGroup_Click
is defined in the source cs file as follows:
protected void btnSearchSuiteGroup_Click(object sender, EventArgs e)
{
this.LinqDataSource1.WhereParameters["SuiteGroupName"].DefaultValue = this.txtSuiteGroupName.Text;
this.GridView1.DataBind();
if (GridView1.Rows.Count == 0)
Response.Write("<script language='javascript'>window.alert('No record found!')</script>");
}
However, when browsing the website, the key press event on the textbox is not initiating the button click event. Is there something wrong in the code?