默认按钮无法正常工作

编程入门 行业动态 更新时间:2024-10-27 00:27:48
本文介绍了默认按钮无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的asp webform中我有一个标准,当用户在文本框中输入驱动程序名称并按回车键时,所有联系人详细信息显示在网格中 由于没有按键事件我使用defaultbutton属性这样做 我的代码看起来像

in my asp 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

更多推荐

默认按钮无法正常工作

本文发布于:2023-11-27 05:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636792.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:无法正常   按钮   工作

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!