在关注不同控件时,默认按钮不起作用

时间:2013-10-18 05:20:26

标签: c# asp.net

我有一个搜索表单,其中我有一些控件(TextBoxDropDownListCheckBox等。)我有一个搜索按钮,其中获取结果集的代码当我点击输入按钮时,我想要搜索按钮点击事件被触发,因为这是写的

<form id="form1" runat="server" defaultbutton="btnSearch">
    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
    </asp:ScriptManager>
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                </telerik:RadCodeBlock>
    <telerik:RadDatePicker ID="RadDatePicker1" Style="display: none;" MinDate="01/01/1900"
        MaxDate="12/31/2100" runat="server">
        <ClientEvents OnDateSelected="dateSelected" />
    </telerik:RadDatePicker>

    <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td align="center" valign="top">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                        <td height="25" align="center" valign="middle">
                            <table width="96%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td width="400" align="left" valign="top">
                                        <span style="color: #FFFFFF; font-weight: bold;">
                                            <asp:Label ID="lblName" runat="server"></asp:Label></span>
                                    </td>

                                    <td align="right" style="color: #FFFFFF; font-weight: bold;">
                                        <asp:LinkButton ID="lbtnLogout" runat="server" Text="Logout" ForeColor="#FFFFFF"
                                            Font-Bold="true" OnClick="lbtnLogout_Click">Logout</asp:LinkButton>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td height="10" align="center" valign="middle">
                        </td>
                    </tr>
                    <tr>
                        <td align="center" valign="top" bgcolor="#FFFFFF">
                            <table width="100%" border="0" cellpadding="0" cellspacing="0" style="background: url(../img/bg02.png) #FFFFFF no-repeat top right;">
                                <tr>
                                    <td align="left" valign="middle">
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr>
                                                <td width="250" align="left">
                                                    <img src="../img/goDigital_Logo01.png" width="198" height="91">
                                                </td>

                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="3" align="center" valign="middle" style="background: url(../img/bg01.png) no-repeat;">
                                        <asp:Label ID="lblError" runat="server" ForeColor="Red"></asp:Label>
                                        <asp:UpdateProgress ID="UpdateProgress2" runat="server">
                                            <ProgressTemplate>
                                                <table cellpadding="0" cellspacing="0" width="140">
                                                    <tr>
                                                        <td width="26">
                                                            <asp:Image ID="Image3" runat="server" ImageAlign="AbsMiddle" Width="16px" Height=" 16px"
                                                                CssClass="PreLoader" ImageUrl="~/Images/preloader-square.gif" />
                                                        </td>
                                                        <td class="HD1b">
                                                            Please wait...
                                                        </td>
                                                    </tr>
                                                </table>
                                            </ProgressTemplate>
                                        </asp:UpdateProgress>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="left" valign="top">
                                        <table width="100%" border="0" cellspacing="2" cellpadding="1" style="background: url(../img/bg-shadow.png) repeat-x center bottom;">

                                            <tr>
                                                <td width="20" class="color2">
                                                    &nbsp;
                                                </td>
                                                <td width="100" class="color2">
                                                    <strong>Vendor Code</strong>
                                                </td>
                                                <td width="5">
                                                    <strong>:</strong>
                                                </td>
                                                <td colspan="2">
                                                    <table cellpadding="0" cellspacing="0" width="80%">
                                                        <tr>
                                                            <td>
                                                                <strong>
                                                                    <telerik:RadComboBox ID="radtxtVendorCode" runat="server" EmptyMessage="Select Vendor Code"
                                                                        EnableLoadOnDemand="true" EnableVirtualScrolling="true" Filter="Contains" HighlightTemplatedItems="true"
                                                                        Height="180px" Style="margin-left: 0px" Width="100%">
                                                                        <WebServiceSettings Method="GetVendorCode" Path="AccountSearch.aspx" />
                                                                    </telerik:RadComboBox>
                                                                </strong>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>

                                                <td width="130" class="color2">
                                                    <strong>Invoice Date</strong>
                                                </td>
                                                <td width="5">
                                                    <strong>:</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadDatePicker ID="RadDPInvoiceDateFrom" runat="server">
                                                            <Calendar ID="Calendar3" runat="server" EnableKeyboardNavigation="true">
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </strong>
                                                </td>
                                                <td>
                                                    <strong>To</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadDatePicker ID="RadDPInvoiceDateTo" runat="server">
                                                            <Calendar ID="Calendar4" runat="server" EnableKeyboardNavigation="true">
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </strong>
                                                </td>
                                            </tr>
                                            <tr>

                                                <td class="color2">
                                                    <strong>Vendor Name</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td colspan="2">
                                                    <table cellpadding="0" cellspacing="0" width="80%">
                                                        <tr>
                                                            <td>
                                                                <strong>
                                                                    <telerik:RadComboBox ID="radtxtVendorName" runat="server" EmptyMessage="Select Vendor Name"
                                                                        EnableLoadOnDemand="true" EnableVirtualScrolling="true" Filter="Contains" Height="180px"
                                                                        HighlightTemplatedItems="true" Style="margin-left: 0px" Width="100%">
                                                                        <WebServiceSettings Method="GetVendorName" Path="AccountSearch.aspx" />
                                                                    </telerik:RadComboBox>
                                                                </strong>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </td>

                                                <td class="color4">
                                                    <strong>Invoice Amount</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadNumericTextBox ID="RadtxtInvoicFromAmt" runat="server" Culture="en-IN"
                                                            EmptyMessage="From Amount" Width="120px">
                                                            <EmptyMessageStyle Font-Italic="True" />
                                                        </telerik:RadNumericTextBox>
                                                    </strong>
                                                </td>
                                                <td>
                                                    <strong>To</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadNumericTextBox ID="RadtxtInvoicToAmt" runat="server" Culture="en-IN"
                                                            EmptyMessage="To Amount" Width="120px">
                                                            <EmptyMessageStyle Font-Italic="True" />
                                                        </telerik:RadNumericTextBox>
                                                    </strong>
                                                </td>
                                            </tr>
                                            <tr>

                                                <td class="color1">
                                                    <strong>Print Ref. No</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td width="160">
                                                    <strong>
                                                        <telerik:RadTextBox ID="RadtxtPrintRefNo" runat="server" EmptyMessage="Enter Print Ref No"
                                                            Width="160px">
                                                            <EmptyMessageStyle Font-Italic="True" />
                                                        </telerik:RadTextBox>
                                                    </strong>
                                                </td>
                                                <td rowspan="3" align="left" valign="top">
                                                    <strong>
                                                        <img src="../img/digital1.jpg" width="160" height="119"></strong>
                                                </td>

                                                <td class="color4">
                                                    <strong>Transaction Date</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadDatePicker ID="RadDTTxnFromDate" runat="server">
                                                            <Calendar ID="Calendar1" runat="server" EnableKeyboardNavigation="true">
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </strong>
                                                </td>
                                                <td>
                                                    <strong>To</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadDatePicker ID="RadDTTxnToDate" runat="server">
                                                            <Calendar ID="Calendar2" runat="server" EnableKeyboardNavigation="true">
                                                            </Calendar>
                                                        </telerik:RadDatePicker>
                                                    </strong>
                                                </td>
                                            </tr>
                                            <tr>

                                                <td class="color4">
                                                    <strong>Invoice No</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadTextBox ID="RadtxtInvoicNo" runat="server" EmptyMessage="Enter Invoic No"
                                                            Width="160px">
                                                            <EmptyMessageStyle Font-Italic="True" />
                                                        </telerik:RadTextBox>
                                                    </strong>
                                                </td>
                                                <td>
                                                    &nbsp;
                                                </td>
                                                <td class="color4">
                                                    <strong>NEFT / Chq No</strong>
                                                </td>
                                                <td>
                                                    <strong>:</strong>
                                                </td>
                                                <td>
                                                    <strong>
                                                        <telerik:RadTextBox ID="RadtxtneftNoFrom" runat="server" EmptyMessage="Enter  From Neft No"
                                                            Width="120px">
                                                            <EmptyMessageStyle Font-Italic="True" />
                                                        </telerik:RadTextBox>
                                                    </strong>
                                                </td>

                                            </tr>
                                            <tr>

                                                <td valign="top" class="color4">
                                                    <strong>Currency</strong>
                                                </td>
                                                <td valign="top">
                                                    <strong>:</strong>
                                                </td>
                                                <td valign="top">
                                                    <strong>
                                                        <telerik:RadComboBox ID="radtxtCurrencyCode" runat="server" Height="121px" HighlightTemplatedItems="true"
                                                            Filter="Contains" EmptyMessage="Select Currency" EnableLoadOnDemand="true" EnableVirtualScrolling="true"
                                                            Width="163px">
                                                            <WebServiceSettings Method="GetCurrencyCode" Path="AccountSearch.aspx" />
                                                        </telerik:RadComboBox>
                                                    </strong>
                                                </td>

                                                <td valign="top" class="color4">
                                                    <strong>Remarks / Naration</strong>
                                                </td>
                                                <td valign="top">
                                                    <strong>:</strong>
                                                </td>
                                                <td colspan="4" valign="top">
                                                    <strong>
                                                        <asp:TextBox ID="txtRemarks" runat="server" Width="330px" TextMode="MultiLine"></asp:TextBox>
                                                    </strong>
                                                </td>
                                            </tr>
                                            <tr>

                                                <td align="left" valign="top">

                                                        <asp:ImageButton ID="btnSearch" runat="server" ImageUrl="~/img/btnsearch.png" Width="125"
                                                            Height="45" OnClick="btnSearch_Click" OnClientClick="return checkdate();" />               
                                                </td>
                                                <td colspan="4" valign="top">
                                                    <asp:ImageButton ID="btnClear" runat="server" ImageUrl="~/img/btnclear.png" Width="125" Height="45" OnClick="btnClear_Click" />
                                            </tr>

                                        </table>
                                    </td>
                                </tr>
                                <tr>
                                    <td height="120" align="left" valign="top" bgcolor="#C2E8F3">
                                        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                                            <ContentTemplate>
                                                <telerik:RadGrid ID="rdSearchResult" runat="server" GridLines="None" AllowPaging="True"
                                                    SkinID="MySkin" AutoGenerateColumns="false" AllowMultiRowSelection="True" AllowSorting="false"
                                                    OnNeedDataSource="rdSearchResult_NeedDataSource" Skin="Windows7">
                                                    <PagerStyle AlwaysVisible="True" />
                                                    <MasterTableView>
                                                        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                                                        <Columns>
                                                            <telerik:GridTemplateColumn HeaderText="Supp Code">
                                                                <ItemTemplate>
                                                                    <%# Eval("suppcode")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Party">
                                                                <ItemTemplate>
                                                                    <%# Eval("party_name")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Ref No">
                                                                <ItemTemplate>
                                                                    <%# Eval("print_refno")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Currency">
                                                                <ItemTemplate>
                                                                    <%# Eval("currcode")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Invoice No">
                                                                <ItemTemplate>
                                                                    <%# Eval("invno")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Invoice Amt">
                                                                <ItemTemplate>
                                                                    <%# Eval("invAmt")%></ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                            <telerik:GridTemplateColumn HeaderText="Invoice Date">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblDate" runat="server" Text='<%#Convert.ToDateTime(Eval("invdt")).ToString("dd/MM/yyyy") %>'></asp:Label>
                                                                </ItemTemplate>
                                                            </telerik:GridTemplateColumn>
                                                        </Columns>
                                                        <PagerStyle AlwaysVisible="True"></PagerStyle>
                                                    </MasterTableView>
                                                    <ClientSettings ClientEvents-OnRowDblClick="rdSearchResultDblClick" EnableRowHoverStyle="true">
                                                        <ClientEvents OnRowDblClick="rdSearchResultDblClick"></ClientEvents>
                                                        <Selecting AllowRowSelect="true" />
                                                    </ClientSettings>
                                                    <SelectedItemStyle BackColor="#C2E8F3" />
                                                </telerik:RadGrid>
                                            </ContentTemplate>
                                        </asp:UpdatePanel>
                                    </td>
                                </tr>

                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td bgcolor="#C44533">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
   </table>
          </form>

但这只适用于我点击某处(将焦点从搜索控件上移开)然后按回车

请建议

4 个答案:

答案 0 :(得分:1)

您可以将控件置于asp:panel内并设置为默认按钮。

<asp:Panel ID="p" runat="server" DefaultButton="myButton">
     <%-- Text boxes here --%>
     <%-- drop down here --%>
     .....
     <asp:Button ID="myButton" runat="server" />
 </asp:Panel>

答案 1 :(得分:1)

设置用户按Enter键时单击的默认按钮?只需将以下行添加到页面的Load事件中,将“btnSearch”替换为按钮名称即可。它使用一个名为RegisterHiddenField的隐藏页面方法,并且工作得非常出色:

Page.RegisterHiddenField("__EVENTTARGET", "btnSearch")

来源: - Default Button

答案 2 :(得分:0)

尝试使用Button及其UseSubmitBehavior

<asp:Button ID="btnSearch" runat="server" Width="125" Height="45" UseSubmitBehavior="true"  />

代替图片按钮。

您可以使用css轻松设置按钮的背景图像。所以不要使用图像按钮

答案 3 :(得分:0)

将此脚本放在scriptmanager下面:

<script type="text/javascript">

    var $p = Telerik.Web.UI.RadComboBox.prototype;

    var keyDownHandler = $p._onKeyDown;

    $p._onKeyDown = function (e) {

        var oReturnValue = e.returnValue;

        var oPreventDefault = e.preventDefault;

        var keyCode = e.keyCode || e.which;

        if (keyCode === 13)

            e.preventDefault = null;

        keyDownHandler.call(this, e);

        if (keyCode === 13) {

            e.returnValue = oReturnValue;

            e.preventDefault = oPreventDefault;

        }

    };

</script>