默认按钮无法正常工作 [英] default button not working correctly

查看:86
本文介绍了默认按钮无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net webform中我有一个标准,当用户在文本框中输入驱动程序名称并按回车键时,所有联系人详细信息显示在网格中



由于没有按键事件我使用defaultbutton属性这样做

我的代码看起来像



in my asp.net webform i ha a criteria when the user enter the driver name in a text box and press enter all the contact details of the sriver is displayed in the grid belo

As there is no keypress event i use defaultbutton property to do so
my code looks like

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DriverTelephoneDetails.aspx.cs" Inherits="NFTRANS.DriverTelephoneDetails" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
    <style type="text/css">
    .style3
    {
        width: 226px;
    }
        .style6
        {
            width: 227px;
        }
        #tblAddnew
        {
            width: 100%;
        }
        .style7
        {
            width: 311px;
        }
        .style8
        {
            width: 110px;
        }
    </style>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p>
    <br />
</p>
<asp:Panel ID="Panel1" runat="server">
    <table class="style1">
        <tr>
            <td class="style3">
                Driver Name :</td>
            <td class="style7">

            <asp:Panel Id="panel2" runat="server" DefaultButton="bt1">
  <asp:TextBox ID="txtDrivername" runat="server" Width="153px"></asp:TextBox>
  <asp:Button id="bt1" Text="Default" runat="server" onclick="bt1_Click" />
</asp:Panel>

              
            </td>
            <td class="style8">

            

                 </td>
            <td>
                <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Add New</asp:LinkButton>
            </td>
        </tr>
    </table>
</asp:Panel>
    <table id="tblAddnew" class="style1"  runat="server" bgcolor="#FF9966" >
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                 </td>
            <td>
                 </td>
        </tr>
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                Code</td>
            <td>
                                     <asp:DropDownList ID="DropDownList1" runat="server" Height="24px" 

                                      Width="190px" AutoPostBack="True">
                                    </asp:DropDownList>
                                    </td>
        </tr>
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                Country</td>
            <td>
                                    <asp:TextBox ID="txtCountry" runat="server" Width="191px"></asp:TextBox>
                                </td>
        </tr>
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                Operator</td>
            <td>
                                    <asp:TextBox ID="txtoperator" runat="server" Width="189px"></asp:TextBox>
                                </td>
        </tr>
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                Telephone</td>
            <td>
                                    <asp:TextBox ID="txt_Phno" runat="server" Width="187px"></asp:TextBox>
                                </td>
        </tr>
        <tr>
            <td bgcolor="#FFCC99" class="style6">
                 </td>
            <td>
                <asp:Button ID="Button1" runat="server" BorderStyle="Double" Text="Submit" 

                    Width="91px" onclick="Button1_Click" />
            </td>
        </tr>
    </table>




     <table class="style1">
         <tr>
             <td>
                  </td>
         </tr>
         <tr>
             <td>
                  </td>
         </tr>
    </table>




     <br />
      <br />





</asp:Content>
















protected void bt1_Click(object sender, EventArgs e)
        {
            DataTable dt = new DataTable();
            SqlConnection con = new SqlConnection(connStr);
            SqlDataReader ddDR = null;
            con.Open();
            SqlCommand cmd = new SqlCommand("SELECT DriverMaster_tbl.Driverid, DriverMaster_tbl.DriverCode, DriverMaster_tbl.FirstName, DriverMaster_tbl.LastName, DriverMaster_tbl.Nationality, DriverPhonenumNew.PhOperator, DriverPhonenumNew.Country, DriverPhonenumNew.PhNum FROM DriverMaster_tbl INNER JOIN DriverPhonenumNew ON DriverMaster_tbl.Driverid = DriverPhonenumNew.DriverId WHERE (DriverMaster_tbl.FirstName LIKE '%" + txtDrivername.Text.Trim() + "%') OR (DriverMaster_tbl.LastName LIKE '%" + txtDrivername.Text.Trim() + "%') ", con);
            ddDR = cmd.ExecuteReader();
            dt.Load(ddDR);



            con.Close();
        }















在我的代码后面我写了一个函数来获取数据>但调试器没有进入bt1_Click()> iam是一个新的bie到web开发并且我确定可能有一些错误,我的任何人都可以指出它.........我使用网页表格与主页








and in my code behind i write a function to fetch data >but the debugger doesnot enter the bt1_Click() >iam a new bie to web development and iam sure there may be some mistake from my part can anyone point it out.........Iam using Web form with master page

推荐答案

你好,





尝试在页面加载中绑定这样的默认按钮。



Hi,


Try binding your default button like this in your pageload.

Page.Form.DefaultButton = bt1.UniqueID;





其中bt1是你的buttonid默认按钮。



这应解决您的问题



Where bt1 is the buttonid of your default button.

This should solve your problem


这篇关于默认按钮无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆