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)
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
|
|
|
|
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)
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.
|
|
|
|
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)
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>
|
|
|
|