|
-
Jun 23rd, 2005, 04:34 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Enter Key on Textfield
Hey there,
i have created a web form and on it are 3 read only textfields, 1 normal textfield and 4 buttons
When data is entered in the textfield i want to be able to call one of the buttons when they hit enter after typing in the data in the textfield.
How could i get this to work
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Jun 23rd, 2005, 07:12 AM
#2
Member
Re: Enter Key on Textfield
C# Code:
Clicking enter in a textbox would normally call the default button on the page.
To override this you need to add some server side code
Code:
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender (e);
TextBox1.Attributes.Add("onkeydown",string.Format("if(window.event.keyCode == 13) {{{0}.focus();}}",Button1.ClientID));
}
VB Code:
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
TextBox1.Attributes.Add("onkeydown", String.Format("if(window.event.keyCode == 13) {{{0}.focus();}}", Button1.ClientID))
End Sub
Note: Dont forget to replace "TextBox1" with the name of your textbox and "Button1" with the name of the button you want to call.
Nikhil Aggarwal

-
Jun 23rd, 2005, 08:09 AM
#3
Thread Starter
Fanatic Member
Re: Enter Key on Textfield
whats the default button on the page.... could i even set this
that code worked great...
what exactly does the prerender event do
Last edited by Strider; Jun 23rd, 2005 at 08:20 AM.
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Jun 24th, 2005, 12:15 AM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|