470,632 Members | 2,554 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,632 developers. It's quick & easy.

TextBox and Button

Hey guys...

In my aspx page I have a textbox that when the user press Return I need to
click a button. How can I do it???

OR

All the pages that contains buttons have a default button, but I don't know
how to define the default button. If I do it, my problem will be solved.
Thank's
Nov 18 '05 #1
6 1410
http://www.dotnetspider.com/Technolo...x?SampleId=212

"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hey guys...

In my aspx page I have a textbox that when the user press Return I need to
click a button. How can I do it???

OR

All the pages that contains buttons have a default button, but I don't
know
how to define the default button. If I do it, my problem will be solved.
Thank's


Nov 18 '05 #2
Hy Ken

I make this:

<asp:textbox id="txtEntrPrCB" onKeyDown="KeyDownHandler('btnEntrPrMa')"
.......

But when I press Enter, I receive this error:

Object doesn't suport this property or method.
WHY????? What I'm doing wrong?
Thank's

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> escreveu na mensagem
news:OF**************@TK2MSFTNGP10.phx.gbl...
http://www.dotnetspider.com/Technolo...x?SampleId=212

"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hey guys...

In my aspx page I have a textbox that when the user press Return I need to click a button. How can I do it???

OR

All the pages that contains buttons have a default button, but I don't
know
how to define the default button. If I do it, my problem will be solved.
Thank's

Nov 18 '05 #3
There may be some errant spaces in the code.

How about this?

Ken

<!-------->
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript">
function KeyDownHandler(btn)
{
// process only the Enter key
if (event.keyCode == 13)
{
// cancel the default submit
event.returnValue=false;
event.cancel = true;
// submit the form by programmatically clicking the specified
button
alert('Clicked');
btn.click();
}
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button Runat="server" ID="DefButton" />
<asp:TextBox Runat="server" ID="FirstName"
onKeyDown="KeyDownHandler(DefButton)" />
</div>
</form>
</body>
</html>
<!-------->

"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
Hy Ken

I make this:

<asp:textbox id="txtEntrPrCB" onKeyDown="KeyDownHandler('btnEntrPrMa')"
......

But when I press Enter, I receive this error:

Object doesn't suport this property or method.
WHY????? What I'm doing wrong?
Thank's

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> escreveu na
mensagem
news:OF**************@TK2MSFTNGP10.phx.gbl...
http://www.dotnetspider.com/Technolo...x?SampleId=212

"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
> Hey guys...
>
> In my aspx page I have a textbox that when the user press Return I need to > click a button. How can I do it???
>
> OR
>
> All the pages that contains buttons have a default button, but I don't
> know
> how to define the default button. If I do it, my problem will be
> solved.
>
>
> Thank's
>
>



Nov 18 '05 #4
Andre,

The code Ken gave you will work, but event.KeyCode will only work for IE and
not netscape. If you want to, I have a bunch of useful javascripts all
rolled into a single component on my website, www.aboutfortunate.com. Click
the code library link on the top right of the page and then click the
javascript button in the menu on the left.

All code on my site is free and the full .NET v1.1 project is downloadable.
So even if you don't want to use the object as is you can get some decent
code examples from it.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:OW**************@tk2msftngp13.phx.gbl...
Hy Ken

I make this:

<asp:textbox id="txtEntrPrCB" onKeyDown="KeyDownHandler('btnEntrPrMa')"
......

But when I press Enter, I receive this error:

Object doesn't suport this property or method.
WHY????? What I'm doing wrong?
Thank's

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> escreveu na mensagem news:OF**************@TK2MSFTNGP10.phx.gbl...
http://www.dotnetspider.com/Technolo...x?SampleId=212

"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hey guys...

In my aspx page I have a textbox that when the user press Return I need
to
click a button. How can I do it???

OR

All the pages that contains buttons have a default button, but I don't
know
how to define the default button. If I do it, my problem will be

solved.

Thank's


Nov 18 '05 #5
hy
here is some code snippet:
-----------------------------------
put next code in Page_Load
TextBox1.Attributes.Add("onkeypress",
"if(event.keyCode==65)Form1.Button1.onclick(); ")
when you press 'A' in TextBox,preseding code excute
Nov 18 '05 #6
You can intercept the client side enter keypress event of the text box and
then do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a couple good articles on the subject:
http://www.allasp.net/enterkey.aspx
http://www.aspnetpro.com/features/20...200406so_f.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"André Almeida Maldonado" <de***@bol.com.br> wrote in message
news:u9**************@TK2MSFTNGP09.phx.gbl...
Hey guys...

In my aspx page I have a textbox that when the user press Return I need to
click a button. How can I do it???

OR

All the pages that contains buttons have a default button, but I don't know how to define the default button. If I do it, my problem will be solved.
Thank's

Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by dskillingstad | last post: by
5 posts views Thread by Steve S | last post: by
1 post views Thread by rn5a | last post: by
5 posts views Thread by Stuart Shay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.