Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Submtting a form in ASP.NET

How do I set up a Google search field in a master page?

4:48 pm on Oct 29, 2008 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 21, 2006
posts: 54
votes: 0

I have a *.aspx Web page that uses a *.master page. The *.master page includes a Google search field. When I type in a search term and press the Enter key, the page seems to submit itself - nothing else happens. The page should forward to Google search results.

The *.master page template uses its own FORM tag. The Google search field also uses its own FORM tag. I'm pretty sure that this is causing the problem.

Here is one of the pages:


Notice that the search button works, but I cannot type a search term and press the Enter key.

Your assistance is greatly appreciated.

5:16 pm on Oct 29, 2008 (gmt 0)


WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
votes: 3

You are correct that the Google search needs its own form tag to work properly as you originally intended.
A alternate solution would be to create the Google search URI in the submit button event and do a Redirect to that after the post back which should achieve the same effect.
5:32 am on Oct 30, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 13, 2005
votes: 0

Yup, common problem. You need to fix it with one line of .Net and some javascript:

q.Attributes.Add("onkeypress", "return clickButton(event, '" & btnSearch.ClientID & "')")
Where 'q' is the ID of your <asp:textbox> and btnSearch is the id of your <asp:Button>

Then, you need the ClickButton javascript code:
function clickButton(e, buttonid){
var bt = document.getElementById(buttonid);
if (typeof bt == 'object'){
if (e.keyCode == 13){
return false;
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
if (event.keyCode == 13){
return false;
} } } }

And you're done. Hitting enter inside the box will now submit the form like someone clicked the Go! button.