0

I have three asp net text boxes that will contain search criteria for searching a table. I would like the search to work like Google. When the enter key is pressed to have the click event on the "Enter" button fire. The click event never fires. What can I do to get it to fire?

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="WebCategoryGenerateEdit.ascx.cs"
Inherits="EPPA.Controls.WebCategoryGenerateEdit" ClientIDMode="Static" %>
<script src="/Scripts/jquery-1.8.3.js" type="text/javascript"></script>
<script type="text/javascript">
//    debugger;
function pageLoad() {
    var gvCategoryMessage = $("#<%=GVCategoryMessage.ClientID %>").html

    if (gvCategoryMessage.length != 0) {
        $("#<%=GVParentCategoryLinkTitle.ClientID %>").keydown(function () {
            $("#<%=GVCategoryMessage.ClientID %>").html("");
        })
        $("#<%=GVCategoryLinkTitle.ClientID %>").keydown(function () {
            $("#<%=GVCategoryMessage.ClientID %>").html("");
        })
    }
}
</script>
<asp:ScriptManager runat="server" />
<asp:MultiView ID="Multiview1" runat="server" ActiveViewIndex="0">
<asp:View ID="SearchView" runat="server">
        <asp:Table ID="TableSV1" runat="server">
            <asp:TableRow ID="TableRowSV1" runat="server">
                <asp:TableCell ID="TableCellSV1" runat="server">
                    <asp:Label ID="LabelSV1" runat="server" SkinID="SearchTextLabel"
Text="CB or CJ" CssClass="searchTextLabel_Division"/>
                </asp:TableCell>
                <asp:TableCell ID="TableCellSV2" runat="server">
                    &nbsp;<asp:Label ID="LabelSV2" runat="server"
SkinID="SearchTextLabel" Text="Parent Category Link Title"
CssClass="searchTextLabel_ParentCategoryLink" />
                </asp:TableCell>
                <asp:TableCell ID="TableCellSV3" runat="server">
                    &nbsp;<asp:Label ID="LabelSV3" runat="server"
 SkinID="SearchTextLabel"
 Text="Category Link Title" CssClass="searchTextLabel_CategoryLink" />
                </asp:TableCell>
                <asp:TableCell ID="TableCellSV4" runat="server">
                    &nbsp;<asp:Label ID="Label1" runat="server" 
 SkinID="SearchTextLabel"
 Text="Category ID" CssClass="searchTextLabel_CategoryID" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow ID="SVTableRowSV2" runat="server">
                <asp:TableCell ID="TableCellSV5" runat="server">
                    <asp:DropDownList ID="SVDivisionDDL" runat="server"
 OnSelectedIndexChanged="SVDivisionDDL_SelectedIndexChanged" AutoPostBack="true" >
                        <asp:ListItem Value="CB">CB</asp:ListItem>
                        <asp:ListItem Value="CJ">CJ</asp:ListItem>
                    </asp:DropDownList>
                    &nbsp;
                </asp:TableCell>            
                <asp:TableCell ID="TableCellSV6" runat="server" >
                   <asp:panel ID="SVPCLTContainer" runat="server"
                    DefaultButton="SV6EnterButton">                       
                      <asp:TextBox ID="SVParentCategoryLinkTitle" runat="server"
                         SkinID="SearchTextBox"
                         CssClass="searchTextBox_ParentCategoryLink"  />
                      <asp:Button ID="SV6EnterButton" runat="server"  Visible="false"
                         Text="Enter" OnClick="EnterKeyPressed_Click" />  
                   </asp:panel>
                   &nbsp;
                </asp:TableCell>            
                <asp:TableCell ID="TableCellSV7" runat="server" >
                    <asp:TextBox ID="SVCategoryLinkTitle"
                         runat="server" SkinID="SearchTextBox" 
                           CssClass="searchTextBox_CategoryLink" />
                    &nbsp;
                </asp:TableCell>            
                <asp:TableCell ID="TableCellSV8" runat="server" >
                    <asp:TextBox ID="SVCategoryID" runat="server"
                       SkinID="SearchTextBox"
                       CssClass="searchTextBox_CategoryID" />
                    &nbsp;
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
    <asp:Button ID="SVGenNewButton" runat="server" Text="Generate New Category ID"
 OnClick="SVGenerateNewButton_Click" />
    &nbsp;
    <asp:Button ID="SVDeleteButton" runat="server" Text="Delete Checked items"
 OnClick="SVDeleteButton_Click" />
    <div style="width:618px; overflow-x:no-display; overflow-y:auto; max-height:392px; 
 padding-top:2px; ">
        <asp:GridView ID="gvWebCategoryID" runat="server" AutoGenerateColumns="False"
 SkinID="gridViewSkin" OnRowDeleting="gvWebCategoryID_RowDeleting" >
            <Columns>
                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                       <asp:Button ID="SVgridViewEditButton" runat="server"
 OnClick="gvWeCategoryIDEditButton_Click" Text="Edit" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete">
                    <ItemTemplate>
                       <asp:CheckBox ID="Checkbox1" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="Division" HeaderText="CB or CJ"
                 Visible="true"  />
                <asp:BoundField DataField="ParentCategoryLinkTitle" HeaderText="Parent
                 Category Link Title" />
                <asp:BoundField DataField="CategoryLinkTitle" HeaderText="Category 
                     Link Title" />
                <asp:BoundField DataField="CategoryID" HeaderText="Category ID" />
                <asp:TemplateField HeaderText="Error Message" Visible="false" >
                    <ItemTemplate>
                       <asp:Label ID="ErrorMessage" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </div>
</asp:View>

</asp:MultiView>        

and here is the behind code method:

    protected void EnterKeyPressed_Click(object sender, EventArgs e)
    {
        ReloadData();
        this.Multiview1.ActiveViewIndex = 0;
    }
Tom3609
  • 11
  • 1
  • 1
  • 4
  • When I set "return true;" The click event for the first button outside of the panel (SVGenNewButton) is fired. – Tom3609 Apr 10 '13 at 13:45

2 Answers2

1

At a quick glance, have you tried removing the return false here:

$("#<%=SVParentCategoryLinkTitle.ClientID %>").keydown(function (e) {
    if (e.which == 13) {
        __doPostBack("#<%=EnterKeyPressed.UniqueID %>", "");
        return false;
    }
})
99823
  • 2,407
  • 7
  • 38
  • 60
0

check out this question and answer, if it helps: Default button not working in asp.net panel

the DefaultButton is used to capture the Enter key press if the focus is already inside the panel, for example you must have moved the focus to an input field like the text boxes inside the panel. if the focus is not there it won't work.

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147
  • To test this I enter a value in the Textbox "SVParentCategoryLinkTitle". WHen I press the enter key the click event of the button "EnterKeyPressed" is still not firing. – Tom3609 Apr 10 '13 at 13:49
  • I did go to the link that you included. In their example, they say that you need an input control other than a button. I do have an asp:textbox control inside the panel. I would like the user to be able to enter text in the asp:textbox and press the enter key to fire the hidden button click event. – Tom3609 Apr 12 '13 at 15:50
  • I have changed the original source code that was displayed above. I surrounded the asp:textbox and asp:button with an asp:panel. The asp:panel has a default button of "SV6EnterButton" (the button inside the panel). – Tom3609 Apr 12 '13 at 16:12