Going Crazy - TextBox KeyPress Event

Author Message
bortiquai

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 5/24/2007
  • Status: offline
Going Crazy - TextBox KeyPress Event Thursday, June 21, 2007 10:14 AM (permalink)
0
I have an ASP.NET TextBox, and want to catch the KeyPress Event.
The TextBox is TextBox1
The Page is Default.Aspx
 
In the Page_Load of the Default.Aspx.VB, I have:
TextBox1.Attributes.Add("OnKeyPress", "GetKeyPress(this)")
 
In the Default.ASPX code, i have:
 
<Script Type="Text/VB">
 
Function GetKeyPress()
    MsgBox("you pressed " & event.KeyCode)
End Function
 
</Script>
 
But I keep Getting "Object Expected" Error.  I've tried about a thousand varieties of this.  It's pretty basic what i am trying to do, but i can't seem to get it.
Can someone help with this code?
Thanks
 
#1
    ebgreen

    • Total Posts : 8227
    • Scores: 98
    • Reward points : 0
    • Joined: 7/12/2005
    • Status: offline
    RE: Going Crazy - TextBox KeyPress Event Friday, June 22, 2007 2:57 AM (permalink)
    0
    I don't do ASP, but here is what I see. This line:
     
    TextBox1.Attributes.Add("OnKeyPress", "GetKeyPress(this)")
     
    Says "Whenever someone presses this key, call the GetKeyPress function and pass an object to it.
     
    This Line:
     
    Function GetKeyPress()
     
    Does not say anything about the function accepting an object.
    "... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
    Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
    http://www.visualbasicscript.com/m_47117/tm.htm
     
    #2
      Rischip

      • Total Posts : 519
      • Scores: 2
      • Reward points : 0
      • Joined: 3/26/2007
      • Status: offline
      RE: Going Crazy - TextBox KeyPress Event Wednesday, July 11, 2007 2:19 PM (permalink)
      0
      Give this a shot:
       
      Default.aspx.vb
       Partial Class _Default
           Inherits System.Web.UI.Page
           Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
               TextBox1.Attributes.Add("onkeypress", "GetKeyPress()")
       
           End Sub
       End Class
       

       
      Default.aspx
       <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[link=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd[/link]">
       <html xmlns="[link=http://www.w3.org/1999/xhtml]http://www.w3.org/1999/xhtml[/link]" >
       <head runat="server">
           <title>Untitled Page</title>
           
           <script language=vbscript>
           Sub GetKeyPress()
           MsgBox "You Pressed" & vbcrlf & _
           "Key Code " & window.event.keyCode & vbcrlf & _
           "Character " & Chr(window.event.keyCode)
           
           End Sub
             
           </script>
       </head>
       <body>
           <form id="form1" runat=server>
           <div>
               <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox></div>
           </form>
       </body>
       </html>
        
       

       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • New Messages
        • No New Messages
        • Hot Topic w/ New Messages
        • Hot Topic w/o New Messages
        • Locked w/ New Messages
        • Locked w/o New Messages
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9