dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 9 of 9

Thread: how to activate button click event by pressing enter key

  1. #1
    Join Date
    May 2007
    Location
    Chennai
    Posts
    35

    Wink how to activate button click event by pressing enter key

    hi,
    I have designed a web part using VS 2003 (Web control library template) using C#. I need to publish that in share point. i have text box and button.

    Button performs search operation. I need to enter a text to be searched and when I click button means the button click event is activated.
    What I need is that if I press the enter button inside the text box means the search function need to be done. In other words button click event should be fired.
    I used key press event but it is not firing. Can any one say the solution....
    Last edited by Rnatarajan1; 05-12-2007 at 05:55 AM.

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    May 2007
    Location
    Chennai
    Posts
    35

    RE:how to activate button click event by pressing enter key

    EmailTextBox.Attributes.Add("onKeyPress", "javascript:if (event.keyCode == 13) __doPostBack('" + LoginButton.UniqueID + "','')");

    instead of LoginButton.UniqueID i called button click event but..the key press event is not firing.

    can anyone help please...


    how can i achieve it

  4. #4
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    this might help:
    (javascript code)
    Code:
    function clickButton(e, btnLogin){ 
          var bt = document.getElementById(btnLogin); 
          if (typeof bt == 'object'){ 
                if(navigator.appName.indexOf("Netscape")>(-1)){ 
                      if (e.keyCode == 13){ 
                            bt.click(); 
                            return false; 
                      } 
                } 
                if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                      if (event.keyCode == 13){ 
                            bt.click(); 
                            return false; 
                      } 
                } 
          } 
    }
    code to be added for your textbox
    Code:
    EmailTextBox.Attributes.Add("onKeyPress", "clickButton(event,'" & LoginButton.ClientID & "')")
    new to programming but getting ther

  5. #5
    Join Date
    May 2007
    Posts
    3
    <asp:Panel ID="LoginPanel" runat="server" DefaultButton="YourButton">
    <asp:TextBox ID="YourTextBox" runat="server" />
    <asp:Button ID="YourButton" runat="server" />
    </asp:Panel>

    The DefaultButton attribute of asp:Panel does the trick

  6. #6
    Join Date
    May 2007
    Location
    Chennai
    Posts
    35
    hi,
    Thanks alot to kumaraparam,Kashif,phil for your quick reply.
    its worknig fine....:-)

  7. #7
    Join Date
    May 2007
    Posts
    3
    No worries mate.

  8. #8
    Join Date
    May 2007
    Posts
    1
    Hello,
    What if there are 2 panels in a web page with different default buttons set, and when press TAB key and arrive at a button in one panel, now press enter key?

    Thanks,
    Vani

  9. #9
    Join Date
    Jun 2004
    Location
    Pakistan
    Posts
    292
    the Panel control creates either a DIV tag or a Table tag depending on your browser, and one more thing Defaultbutton is for 2.0, not 1.1 framework. For 1.1/0, you will have to use JavaScript if you have more than one button.
    new to programming but getting ther

Similar Threads

  1. Enter Key Press
    By PW in forum .NET
    Replies: 2
    Last Post: 02-11-2003, 12:17 PM
  2. Enter Key Bug in UserControl?
    By Jim Pragit in forum .NET
    Replies: 2
    Last Post: 03-31-2002, 12:51 PM
  3. Replies: 2
    Last Post: 11-27-2001, 06:26 PM
  4. Submit form with Enter key?
    By comdna in forum ASP.NET
    Replies: 2
    Last Post: 02-22-2001, 11:21 AM
  5. Replies: 0
    Last Post: 12-01-2000, 06:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center