homepage Welcome to WebmasterWorld Guest from 54.205.189.156
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
Submtting a form in ASP.NET
How do I set up a Google search field in a master page?
rcshield




msg:3775949
 4:48 pm on Oct 29, 2008 (gmt 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:

[calbaptist.edu...]

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

Your assistance is greatly appreciated.

 

Ocean10000




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

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.

carguy84




msg:3776442
 5:32 am on Oct 30, 2008 (gmt 0)

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

.net:
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(navigator.appName.indexOf("Netscape")>(-1)){
if (e.keyCode == 13){
bt.click();
return false;
}
}
if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){
if (event.keyCode == 13){
bt.click();
return false;
} } } }

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

Chip-

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved