By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,659 Members | 940 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,659 IT Pros & Developers. It's quick & easy.

Need Enter key to trigger post

P: n/a
I have a function that looks up a SQL table to see if a search term matches.
It works fine but so far there are two things yet to work:

1) After entering a search term and pressing Enter, nothing has been
happening. It has only been searching when I click the Search button.

2) Neither of the Response.Write's have been displaying any text.

Here's the code:

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="SearchBox" runat="server" Width="168px"
AutoPostBack="True"
TabIndex="1"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Text="Search" TabIndex="2" />

</div>
</form>
</body>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("Test")
If fVerifySearch(Me.SearchBox.Text) = False Then
Response.Write("No record found.")
End If

End Sub

Jun 27 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
HI
Write a simple javascript that trap the textbox's keydown event...
if keycode is enter... call the from.submit or raise the click
function of the button
Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
Jun 27 '08 #2

P: n/a
you specified autopostback on the textfield, so hitting return only fires the
change event.

-- bruce (sqlwork.com)
"Mark B" wrote:
I have a function that looks up a SQL table to see if a search term matches.
It works fine but so far there are two things yet to work:

1) After entering a search term and pressing Enter, nothing has been
happening. It has only been searching when I click the Search button.

2) Neither of the Response.Write's have been displaying any text.

Here's the code:

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="SearchBox" runat="server" Width="168px"
AutoPostBack="True"
TabIndex="1"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" TabIndex="2" />

</div>
</form>
</body>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("Test")
If fVerifySearch(Me.SearchBox.Text) = False Then
Response.Write("No record found.")
End If

End Sub

Jun 27 '08 #3

P: n/a
Hi Mark,

As for the first question, you can add some javascript for the
TextBox(input field)'s "onkeydown" event and post the form. Here are some
web articles mentioned this:

#Enter Key in ASP.NET - Complete Research
http://www.beansoftware.com/ASP.NET-...Enter-Key.aspx

#Default Button Submissions in ASP.NET Pages
http://www.west-wind.com/WebLog/posts/1225.aspx

#Setting the default Button for a TextBox in ASP.NET
http://weblogs.asp.net/rajbk/archive...fault-button-f
or-a-textbox-in-asp-net.aspx

For the second question, "Response.Write" will always output the parameter
from the begining of the response stream, therefore, your output will
generally display at the top of the page. Also, if you want to display some
message on page to users, I suggest you use the following means instead of
Response.Write:
You can put a Label control on the page. And then in your page's codebehind
use label.Text = "xxxx" to display the information. The advantage of this
is that the text content can be embeded correctly inside the HTML body/form
instead of at the begining of response stream.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
>From: "Mark B" <no**@none.com>
Subject: Need Enter key to trigger post
Date: Mon, 16 Jun 2008 12:40:09 +1200
>
I have a function that looks up a SQL table to see if a search term
matches.
>It works fine but so far there are two things yet to work:

1) After entering a search term and pressing Enter, nothing has been
happening. It has only been searching when I click the Search button.

2) Neither of the Response.Write's have been displaying any text.

Here's the code:

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="SearchBox" runat="server" Width="168px"
AutoPostBack="True"
TabIndex="1"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Text="Search" TabIndex="2" />

</div>
</form>
</body>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("Test")
If fVerifySearch(Me.SearchBox.Text) = False Then
Response.Write("No record found.")
End If

End Sub

Jun 27 '08 #4

P: n/a
I just took AutoPostBack out. It didn't make a difference.

Also any idea why the response.write's haven't worked?

The entire code is below if you want to test it.
"bruce barker" <br*********@discussions.microsoft.comwrote in message
news:2C**********************************@microsof t.com...
you specified autopostback on the textfield, so hitting return only fires
the
change event.

-- bruce (sqlwork.com)
"Mark B" wrote:
>I have a function that looks up a SQL table to see if a search term
matches.
It works fine but so far there are two things yet to work:

1) After entering a search term and pressing Enter, nothing has been
happening. It has only been searching when I click the Search button.

2) Neither of the Response.Write's have been displaying any text.

Here's the code:

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="SearchBox" runat="server" Width="168px"
AutoPostBack="True"
TabIndex="1"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" TabIndex="2" />

</div>
</form>
</body>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("Test")
If fVerifySearch(Me.SearchBox.Text) = False Then
Response.Write("No record found.")
End If

End Sub

Jun 27 '08 #5

P: n/a
When I used to use FrontPage (a few weeks ago before downloading Visual Web
Developer 2008 Express), all I did was insert a button on a webpage and it
defaulted to be a submit button as well as automatically created a form. So
from there whenever I pressed Enter on the webpage it automatically
submitted.

Now with VWDExpress 2008 I tried to do the same thing; that is drag a button
and then a text box onto a blank webpage.

There seems to be no automatic creation of a form and a submit button. I'll
plan have a read through the articles you mentioned and see if they do allow
me to emulate the FrontPage generated functionality.

Thanks.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:1Q**************@TK2MSFTNGHUB02.phx.gbl...
Hi Mark,

As for the first question, you can add some javascript for the
TextBox(input field)'s "onkeydown" event and post the form. Here are some
web articles mentioned this:

#Enter Key in ASP.NET - Complete Research
http://www.beansoftware.com/ASP.NET-...Enter-Key.aspx

#Default Button Submissions in ASP.NET Pages
http://www.west-wind.com/WebLog/posts/1225.aspx

#Setting the default Button for a TextBox in ASP.NET
http://weblogs.asp.net/rajbk/archive...fault-button-f
or-a-textbox-in-asp-net.aspx

For the second question, "Response.Write" will always output the parameter
from the begining of the response stream, therefore, your output will
generally display at the top of the page. Also, if you want to display
some
message on page to users, I suggest you use the following means instead of
Response.Write:
You can put a Label control on the page. And then in your page's
codebehind
use label.Text = "xxxx" to display the information. The advantage of this
is that the text content can be embeded correctly inside the HTML
body/form
instead of at the begining of response stream.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.


--------------------
>>From: "Mark B" <no**@none.com>
Subject: Need Enter key to trigger post
Date: Mon, 16 Jun 2008 12:40:09 +1200
>>
I have a function that looks up a SQL table to see if a search term
matches.
>>It works fine but so far there are two things yet to work:

1) After entering a search term and pressing Enter, nothing has been
happening. It has only been searching when I click the Search button.

2) Neither of the Response.Write's have been displaying any text.

Here's the code:

<body>
<form id="form1" runat="server">
<div>

<asp:TextBox ID="SearchBox" runat="server" Width="168px"
AutoPostBack="True"
TabIndex="1"></asp:TextBox>
&nbsp;<asp:Button ID="Button1" runat="server" Text="Search" TabIndex="2"
/>

</div>
</form>
</body>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write("Test")
If fVerifySearch(Me.SearchBox.Text) = False Then
Response.Write("No record found.")
End If

End Sub

Jun 27 '08 #6

P: n/a
Thanks for your quick reply Mark,

For the front page behavior, it is actually abit related to the
webbrowser's handling of key press when you have focus on a textbox in
browser. When your page have some textbox and submit button on page, and if
you press enter key (when focus on a textbox), the browser will submit the
page/form. this is also true for ASP.NET page, however, ASP.NET button's
"click" event is not a simple form submit, so that won't work if you need
to invoke button's postback event.

Actually, in addition to the javascript approach(I mentioned eariler which
is the most reliable and common means), you can also use the
"defaultButton" feature in ASP.NET page. For example:

#set default button attribute for <formto the ID of the button control
=================
<form id="form1" runat="server" defaultbutton="Button1" >
<div>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />

</div>
</form>
=============

You can also apply default button on a Panel control. e.g.

=============
<asp:panel defaultbutton=ˇ±btnOKˇ± runat=ˇ±serverˇ±>
......
</asp:panel>
=============

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
>From: "Mark B" <no**@none.com>
References: <en**************@TK2MSFTNGP03.phx.gbl>
<1Q**************@TK2MSFTNGHUB02.phx.gbl>
>In-Reply-To: <1Q**************@TK2MSFTNGHUB02.phx.gbl>
Subject: Re: Need Enter key to trigger post
Date: Tue, 17 Jun 2008 14:37:14 +1200

When I used to use FrontPage (a few weeks ago before downloading Visual
Web
>Developer 2008 Express), all I did was insert a button on a webpage and it
defaulted to be a submit button as well as automatically created a form.
So
>from there whenever I pressed Enter on the webpage it automatically
submitted.

Now with VWDExpress 2008 I tried to do the same thing; that is drag a
button
>and then a text box onto a blank webpage.

There seems to be no automatic creation of a form and a submit button.
I'll
>plan have a read through the articles you mentioned and see if they do
allow
>me to emulate the FrontPage generated functionality.

Thanks.

"Steven Cheng [MSFT]" <st*****@online.microsoft.comwrote in message
news:1Q**************@TK2MSFTNGHUB02.phx.gbl...
>Hi Mark,

As for the first question, you can add some javascript for the
TextBox(input field)'s "onkeydown" event and post the form. Here are some
web articles mentioned this:

#Enter Key in ASP.NET - Complete Research
http://www.beansoftware.com/ASP.NET-...Enter-Key.aspx

#Default Button Submissions in ASP.NET Pages
http://www.west-wind.com/WebLog/posts/1225.aspx

#Setting the default Button for a TextBox in ASP.NET
http://weblogs.asp.net/rajbk/archive...fault-button-f
>or-a-textbox-in-asp-net.aspx

For the second question, "Response.Write" will always output the
parameter
>from the begining of the response stream, therefore, your output will
generally display at the top of the page. Also, if you want to display
some
message on page to users, I suggest you use the following means instead
of
>Response.Write:
Jun 27 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.