2013-04-09 86 views
0

我有三個asp網絡文本框,將包含搜索表的搜索條件。我希望搜索能像谷歌一樣工作。按下回車鍵以激活「Enter」按鈕上的點擊事件。點擊事件從不會觸發。我能做些什麼來讓它着火?我如何得到asp:面板默認按鈕發射按鈕單擊事件?

<%@ 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>   

這裏是後臺代碼方法:

protected void EnterKeyPressed_Click(object sender, EventArgs e) 
    { 
     ReloadData(); 
     this.Multiview1.ActiveViewIndex = 0; 
    } 
+0

當我設置「返回true;」觸發面板外部第一個按鈕(SVGenNewButton)的點擊事件。 – Tom3609 2013-04-10 13:45:35

回答

0

退房這個問題和答案,如果它可以幫助:Default button not working in asp.net panel

DefaultButton被用來捕捉Enter按鍵,如果焦點已經在面板內部,例如,您必須將焦點移至輸入字段,如面板內的文本框。如果焦點不在那裏,它將無法工作。

+0

要測試這個,我在文本框「SVParentCategoryLinkTitle」中輸入一個值。當我按下回車鍵時,「EnterKeyPressed」按鈕的點擊事件仍然沒有開火。 – Tom3609 2013-04-10 13:49:52

+0

我確實轉到了包含的鏈接。在他們的例子中,他們說你需要一個按鈕以外的輸入控件。我在面板裏有一個asp:textbox控件。我希望用戶能夠在asp:文本框中輸入文本,然後按回車鍵來觸發隱藏的按鈕單擊事件。 – Tom3609 2013-04-12 15:50:14

+0

我更改了上面顯示的原始源代碼。我用asp:面板包圍了asp:textbox和asp:button。 asp:面板有一個默認的「SV6EnterButton」按鈕(面板內的按鈕)。 – Tom3609 2013-04-12 16:12:01

1

快速瀏覽,你嘗試過在這裏假取出回報:

$("#<%=SVParentCategoryLinkTitle.ClientID %>").keydown(function (e) { 
    if (e.which == 13) { 
     __doPostBack("#<%=EnterKeyPressed.UniqueID %>", ""); 
     return false; 
    } 
})