Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET HTML
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();
        }
 

 

 

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 21-Feb-13 1:55am
Edited 21-Feb-13 2:18am
v3
Comments
N@veen.S at 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.G at 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
N@veen.S at 21-Feb-13 7:12am
   
can you provide your source code....
SREENATH.G at 21-Feb-13 7:14am
   
i updated my question pls see it
N@veen.S at 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...
SREENATH.G at 21-Feb-13 7:27am
   
i will set that datatable dt as the datasource of a gridview but the problem is this this query blow in not being executed.
N@veen.S at 21-Feb-13 7:28am
   
you face the problem in select query right..?
SREENATH.G at 21-Feb-13 7:36am
   
no @naveen my select query is working perfectly my issue is that when i press enter in the textbox the default button click event is not being triggered
Ed Nutting at 21-Feb-13 7:47am
   
You realise that the enter key will only cause a click event on the button if the button has focus. If the textbox has focus, then it will fire a keydown/up event on the textbox but not submit the form. Just write a small piece of js code that calls form.submit() when the enter key is pressed.
 
(It may not be perfect, but it is a good, general purpose blanket solution :))
Ed
SREENATH.G at 21-Feb-13 7:53am
   
@naveen Default button doesnot require an focus to trigger ..anyway iam going to do the js for the meanwhile but this is a issue..and one more thing webform textbox doesnot have an keydown or keypress event
N@veen.S at 21-Feb-13 8:02am
   
All d best but previous comment written by Ed Nutting
SREENATH.G at 21-Feb-13 8:03am
   
:) sorry @naveen
N@veen.S at 21-Feb-13 7:30am
   
your select query returns any value...?
 
upto now your not given exact information , what's the problem you facing please mentioned that...
N@veen.S at 21-Feb-13 7:26am
   
I think your requirement is based upon search value you want to display the information in DDL...?
 

righ...?
SREENATH.G at 21-Feb-13 7:34am
   
@naveeen Query is returning value, when I physically click the defaultbutton it gives the datatable filled but when I type in the drivername and press enter that block is not executed
N@veen.S at 21-Feb-13 7:41am
   
Without enter text value you got the result...
But when you try to search some text in TextBox and then click on button at that time your searching result is blank...right...?
SREENATH.G at 21-Feb-13 7:45am
   
@naveen Soory if i confused you
 
Please look on the issue
 
Scenario 1: I entered the drivername on the textbox and cliked on the default button.......I get the datatable filled
Scenario 2 : I entered the drivername on the textbox and without leaving the focus from the textbox I press enter .....I didnt get any datatable filled
N@veen.S at 21-Feb-13 7:55am
   
Sorry yar i'm try to resolve this issue , but still now i'm confusing about your requirement.
Your DataTable returns empty records means that's the problem of your Select Query only.
I understand the scenario 1, but i can't understand scenario 2..
N@veen.S at 21-Feb-13 7:43am
   
your searching based on driver name , in this case your query returns any value
Sanjeev Alamuri at 21-Feb-13 7:26am
   
First u click on "Default" button. it will take u into function bt1_Click(), if it dont, then we will see the error where it is!!!
one more Request, Please change all "onclick" into "onClick".
SREENATH.G at 21-Feb-13 7:32am
   
@sanjeev when iam clicking the default button its working and iam able to get a datatable filled ...but with enter button iam not able to get that same module run
Sanjeev Alamuri at 21-Feb-13 7:49am
   
Check ur tab index value of your button!! after Textbox it must be Button!!! then it will works!!
Ed Nutting at 21-Feb-13 7:35am
   
Capitalisation is irrelevant - HTML and HTML attributes are not case sensitive. (Names are not case-sensitive, values are of course...)
SREENATH.G at 21-Feb-13 7:39am
   
<asp:Panel Id="panel2" runat="server" DefaultButton="bt1">
<asp:TextBox ID="txtDrivername" runat="server" Width="153px">
<asp:Button id="bt1" Text="Default" runat="server" onclick="bt1_Click" />

 
it is bt1_Click itself
Ed Nutting at 21-Feb-13 7:40am
   
My apologies...in your mess of HTML I missed the button that actually had onclick set to bt1_Click (you really should name/label things better!)
 
Taking a second look now,
Ed
SREENATH.G at 21-Feb-13 7:55am
   
My appologies too.. Iam not a good webdeveloper this is my first webpage and iam a windows form developer till now so my html may be little bit messy

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 

Try binding your default button like this in your pageload.
 
Page.Form.DefaultButton = bt1.UniqueID;
 
Where bt1 is the buttonid of your default button.
 
This should solve your problem
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 319
1 Kornfeld Eliyahu Peter 265
2 Maciej Los 249
3 BillWoodruff 205
4 Sergey Alexandrovich Kryukov 175
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 21 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100