- ASP.NET WP - Publish
- ASP.NET WP - Security
- ASP.NET WP - Caching
- Add Social Networking to the Website
- ASP.NET WP - Add Search
- ASP.NET WP - Add Email
- ASP.NET WP - Working with Videos
- ASP.NET WP - Working with Images
- ASP.NET WP - Working with Files
- ASP.NET WP - Charts
- ASP.NET WP - WebGrid
- ASP.NET WP - Delete Database Data
- ASP.NET WP - Edit Database Data
- ASP.NET WP - Add Data to Database
- ASP.NET WP - Database
- ASP.NET WP - Page Object Model
- ASP.NET WP - Working with Forms
- ASP.NET WP - Layouts
- ASP.NET WP - Programming Concepts
- ASP.NET WP - Global Pages
- Project Folder Structure
- ASP.NET WP - View Engines
- ASP.NET WP - Getting Started
- ASP.NET WP - Environment Setup
- ASP.NET WP - Overview
- ASP.NET WP - Home
ASP.NET WP Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ASP.NET WP - Add Search
In this chapter, we will be covering how to add search functionapty in your website using the Microsoft Bing search engine. Adding a search functionapty to your website is very easy, you can use the Bing helper and specify the URL of the site to search. The Bing helper renders a text box where users can enter a search term.
By adding the capabipty to search, you can also include Internet search results without leaving your site. You can use the Search option in the following ways −
Add a Search, the dialog box in which a user can search your site only which makes it easy for users to find content on your site.
Add a box that lets the users to easily search the related sites.
Add a box that lets users search the Web, but without having to leave your site. This can be done by launching that search in another window.
There are two types of search options that you can use in your website.
Simple search
Advanced search
Simple Search
In this simple search option, the helper renders a box that includes the Bing search icon which users can cpck in order to launch the search.
In a simple search, the helper will also render radio buttons in which the user can specify whether to search only the specified site or the web in general.
When the user submits the search, the simple option just redirects the search to the Bing site −
.Then the results will be displayed in a new browser window, pke user is searching in the Bing home page.
Advanced Search
In the advanced option, the helper will render a search box without radio buttons. In this case, the helper gets the search results and then formats and displays them right in that page instead of just redirecting to the Bing site.
Let’s have a look into a simple example of search by creating a new CSHTML file.
Enter Search.cshtml file in the Name field and cpck OK.
Replace the following code in the Search.cshtml file.
<!DOCTYPE html> <html> <head> <title>Custom Bing Search Box</title> </head> <body> <span> <h1>Simple Search</h1> <p>The simple option displays results by opening a new browser window that shows the Bing home page.</p> Search the ASP.NET site: <br/> @Bing.SearchBox(siteUrl: "www.asp.net") </span> </body> </html>
As you can see in the above code, the siteUrl parameter in the @Bing.SearchBox() is optional, which means that you can specify the user has the option of which site to search. If you don’t specify a URL, then Bing will search the web.
You can see that we have specified the www.asp.net website, so it will search that site, but if you want to search your own site, then you will need to specify that URL instead of
.Let’s run the apppcation and specify the following url − http://localhost:36905/Search and you will see the following output.
Let’s enter some text to search in the search box.
Press enter and you will see that the Microsoft Bing home page opens in another tab.
Advertisements