Click here to Skip to main content
15,868,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

ASP.NET
<%@ 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>





C#
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();
        }







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
Posted
Updated 21-Feb-13 1:18am
v3
Comments
Naveen.Sanagasetti 21-Feb-13 7:04am    
What's the problem now ...?
Any error you got...?
your given some improper information...
How to workout using this information...?
please provide your source code also..
And where your facing problem , that's also you should mentioned..

what's the meaning of this
but the debugger doesnot enter the bt1_Click() ...?
SREENATH GANGA 21-Feb-13 7:10am    
means all is fine but when i press the enter key in debug mode it never enters the function bt1_Click() which is the click function of the default button
Naveen.Sanagasetti 21-Feb-13 7:12am    
can you provide your source code....
SREENATH GANGA 21-Feb-13 7:14am    
i updated my question pls see it
Naveen.Sanagasetti 21-Feb-13 7:24am    
you try to display the information ... right...?
your using select query , where to display that information...
I can't understand your exact requirement...

1 solution

Hi,


Try binding your default button like this in your pageload.

C#
Page.Form.DefaultButton = bt1.UniqueID;


Where bt1 is the buttonid of your default button.

This should solve your problem
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900