ASP.NET搜索字段输入按钮问题

时间:2011-02-10 20:11:36

标签: asp.net webforms

我有一个网页,上面有3个搜索字段,每个字段都有不同的提交按钮。当使用键盘上的enter按钮提交任何一个时,正在执行不正确的操作,尽管使用鼠标就可以了。

为什么会发生这种情况?

以下要求呈现的HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head id="ctl00_ctl00_Head1">


<body id="home">

    <form name="aspnetForm" method="post" action="history_lookup.aspx?theme=t2" id="aspnetForm">

<div>

<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />

<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwULLTE1MzkzOTQxNDBkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYFBSZjdGwwMCRjdGwwMCRNaW5pQ2FydFRleHQxJEltYWdlQnV0dG9uMQUsY3RsMDAkY3RsMDAkVG9wTmF2JFF1aWNrU2VhcmNoMSRJbWFnZUJ1dHRvbjIFLGN0bDAwJGN0bDAwJFRvcE5hdiRRdWlja1NlYXJjaDEkSW1hZ2VCdXR0b24xBShjdGwwMCRjdGwwMCRjcGhSb290JGNwaFN1Yk1hc3RlciRzdWJtaXQxBShjdGwwMCRjdGwwMCRjcGhSb290JGNwaFN1Yk1hc3RlciRzdWJtaXQy4UTdoX+Ej1GFsXGOrI898SMftDA=" />

</div>


<script type="text/javascript">

//<![CDATA[

var theForm = document.forms['aspnetForm'];

if (!theForm) {

    theForm = document.aspnetForm;

}

function __doPostBack(eventTarget, eventArgument) {

    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {

        theForm.__EVENTTARGET.value = eventTarget;

        theForm.__EVENTARGUMENT.value = eventArgument;

        theForm.submit();

    }

}

//]]>

</script>





<script src="/WebResource.axd?d=gfGwAOwAxcQ9Nlq6l3EJfg2&amp;t=634166396192656250" type="text/javascript"></script>

<div>

    <input type="hidden" name="__PREVIOUSPAGE" id="__PREVIOUSPAGE" value="fwZ-2v_x8CYGGr9a8Ce0s6gkE38QmubHNljKJaKxZV41" />

    <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWCAKs3Nu8DwLV2a2zBwKK/6PwCQLBpvyBBAKT+aizBgL+qMTTDwLU1/SWCwL+qNiuCArtGFkuC9Zj3X3If1cwPC7PKtcm" />

</div>

        <div class="container clearfix" style="left: 0px; top: 0px">

            <div class="utilityNav">

        <a class="MenuItem" href="/extranet.aspx?theme=t2" title="Account Info">

            Account Info

            </a>


            &nbsp;|&nbsp;



        <a class="MenuItem" href="/history_lookup.aspx?theme=t2" title="Order History">

            Order History

            </a>


            &nbsp;|&nbsp;

        <a class="MenuItem" href="/_user_logout.aspx" title="Sign Off">

            Sign Off

            </a>

            </div>                

            <div class="header">

                <div class="cart" >

    <div id="menu">

             <div class="cartimage">

              <input type="image" name="ctl00$ctl00$MiniCartText1$ImageButton1" id="ctl00_ctl00_MiniCartText1_ImageButton1" src="images/bg-cart-corner.gif" align="left" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$MiniCartText1$ImageButton1&quot;, &quot;&quot;, false, &quot;&quot;, &quot;cart.aspx&quot;, false, false))" style="border-width:0px;" />

        </div>


            <div class="cartlabel">Checkout Cart:<br />

         <a id="ctl00_ctl00_MiniCartText1_lbMiniCart2" class="cartlink" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$MiniCartText1$lbMiniCart2&quot;, &quot;&quot;, false, &quot;&quot;, &quot;cart.aspx?theme=t2&quot;, false, true))">View your cart</a>

        </div>


        <br /><br />

    </div>

                </div>

            </div>



<div class="primaryNav">



        <div class="navdropdown">

              </div>

         <div align="right" class="quicksearch">

<div class="QuickSearch">

    <div id="ctl00_ctl00_TopNav_QuickSearch1_quicksearchpanel" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'ctl00_ctl00_TopNav_QuickSearch1_ImageButton1')">


        <table cellpadding="0" cellspacing="0" class="QuickSearch">

            <tr>

                <td class="quicksearch_text">

                    <span id="ctl00_ctl00_TopNav_QuickSearch1_lblSearch"></span>

                </td>

                <td >

                    <input class="QuickSearch" type="text" name="searchstring" size="15" maxlength="30" value="Search" onfocus="if (this.value == 'Search') {this.value = '';}" onblur="if (this.value == '') {this.value = 'Search';}"  />

                </td>

                <td class="quicksearch_button">



                                <input type="image" name="ctl00$ctl00$TopNav$QuickSearch1$ImageButton2" id="ctl00_ctl00_TopNav_QuickSearch1_ImageButton2" src="images/searchbutton.gif" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ctl00$TopNav$QuickSearch1$ImageButton2&quot;, &quot;&quot;, false, &quot;&quot;, &quot;/Searchdh.aspx?theme=t2&quot;, false, false))" style="border-width:0px;" />


                </td>

            </tr>

        </table>

</div>

</div>

         </div>

</div>

        <td valign="top">

    <div class="HistoryLookupPage">

<h1 class="PageHeader">

    <span id="ctl00_ctl00_cphRoot_cphSubMaster_PageHeader1_LabelHeader">Order History</span>

</h1>

        <p>

            Enter the reference number of the order you want to see.

        </p>

        <p>

            Reference number

            <input name="ctl00$ctl00$cphRoot$cphSubMaster$CustomerReference" type="text" id="ctl00_ctl00_cphRoot_cphSubMaster_CustomerReference" class="borderTextBox" />

            <input type="image" name="ctl00$ctl00$cphRoot$cphSubMaster$submit1" id="ctl00_ctl00_cphRoot_cphSubMaster_submit1" src="images/buttons/findorder-blue.gif" style="border-width:0px;" />

        </p>

                <br />

                <p><b>Or search by PO Number</b></p>



                <p>



            <input name="ctl00$ctl00$cphRoot$cphSubMaster$CustomerReference2" type="text" id="ctl00_ctl00_cphRoot_cphSubMaster_CustomerReference2" class="borderTextBox" />

            <input type="image" name="ctl00$ctl00$cphRoot$cphSubMaster$submit2" id="ctl00_ctl00_cphRoot_cphSubMaster_submit2" src="images/buttons/findorder-blue.gif" style="border-width:0px;" />

        </p>        

    </div>

        </td>

        </tr>

        </table>

        </div>

    </form>

</body>

</html>

和aspx标记

<%@ Import Namespace="System.Configuration.ConfigurationManager" %>

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="history_lookup.aspx.vb"
    EnableViewState="false" Inherits="history_lookup" ValidateRequest="false" CodeFileBaseClass="Main.Page"
    MasterPageFile="~/masters/default/main.master" RuntimeMasterPageFile="ThreeColumn.master"
    CrumbName="<%$ Resources: Language, LABEL_MENU_HISTORY %>" %>


<%@ Register Src="~/controls/Message.ascx" TagName="Message" TagPrefix="uc1" %>
<%@ Register Src="~/controls/PageHeader.ascx" TagName="PageHeader" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphSubMaster" runat="Server">

        <td valign="top">
    <div class="HistoryLookupPage">
        <uc1:Message ID="Message1" runat="server" />
        <uc1:PageHeader ID="PageHeader1" runat="server" Text="<%$ Resources: Language, LABEL_MENU_HISTORY %>"
            EnableTheming="true" />
        <p>
            <asp:Literal ID="Literal1" runat="server" Text="<%$ Resources: Language, LABEL_PLEASE_ENTER_ORDERREF %>"></asp:Literal>
        </p>
        <p>
            <asp:Literal ID="Literal2" runat="server" Text="<%$ Resources: Language, LABEL_HISTORY_LOOKUP %>"></asp:Literal>
            <asp:TextBox runat="server" ID="CustomerReference" CssClass="borderTextBox" />
<%--            <asp:Button ID="Button1" runat="server" CssClass="BtnC" Text="<%$ Resources: Language, ACTION_LOOKUP %>" />
--%>            <asp:ImageButton ID="submit1" runat="server" imageurl="~/images/buttons/findorder-blue.gif" />
        </p>
                <% if Not globals.User("Anonymous") then %>
                <br />
                <p><b>Or search by PO Number</b></p>

                <p>

            <asp:TextBox runat="server" ID="CustomerReference2" CssClass="borderTextBox" />
<%--            <asp:Button ID="Button2" runat="server" CssClass="BtnC" Text="Find Order" />
--%>            <asp:ImageButton ID="submit2" runat="server" imageurl="~/images/buttons/findorder-blue.gif" />
        </p>

                <% end if %>
    </div>
        </td>
        </tr>
        </table>
</asp:Content>

1 个答案:

答案 0 :(得分:3)

在asp:面板中包含每组字段,然后将每个asp:面板的默认按钮设置为正确的按钮ID。问题是它默认为错误的提交按钮。