Knowledgebase Home Page  >  SearchUnit  >  Version 2 Articles
Search the Knowledge Base
Is it possible to have both the search box and the search result control on the same page?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=82&catId=66

Options

Print this page
Email this to a friend
Yes.
 
1. Drag both controls onto a form.
 
2. In the Page_Load in the codebehind insert this code
 
//C#
if(Request.Params["QueryExpr"] == null)
     this.SearchResult1.Visible = false;
 
'VB.NET
If Request.Params["QueryExpr"] Is Nothing Then
     this.SearchResult1.Visible = false
End If
 
3. In the SearchBox control set the ResultPageURL to the current page.
 
This of course assumes your SearchResult control is named SearchResult1.
 
 
 
 
 
Here's a complete example.
 
ASPX
-------
 

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="KeyotiSearchDemo_CSharp.WebForm1" %>
<%@ Register TagPrefix="searchengine" Namespace="Keyoti.SearchEngine.Web" Assembly="Keyoti.SearchEngine.Web, Version=1.1.1.28286, Culture=neutral, PublicKeyToken=58d9fd2e9ec4dc0e" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>WebForm1</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout">
  <form id="Form1" method="post" runat="server">
   <SearchEngine:SearchBox id="SearchBox1" style="Z-INDEX: 101; LEFT: 63px; POSITION: absolute; TOP: 62px"
    runat="server" ResultPageURL-Length="13" ResultPageURL="WebForm1.aspx">
    <SearchButton BorderWidth="" BorderColor="" ForeColor="" BackColor="" Height="" Width="" CssClass=""
     type="button" value="Search" onClick="__doPostBack('SearchBox1','')"></SearchButton>
    <QueryTextBox Width="" BorderWidth="" BorderColor="" ForeColor="" BackColor="" Height="" CssClass=""
     type="text"></QueryTextBox>
   </SearchEngine:SearchBox>
   <searchengine:SearchResult id="SearchResult1" style="Z-INDEX: 102; LEFT: 133px; POSITION: absolute; TOP: 119px"
    runat="server" IndexDirectory-Length="57" IndexDirectory="c:\inetpub\wwwroot\keyotisearchdemo_csharp\indexdirectory">
    
   </searchengine:SearchResult>
  </form>
 </body>
</HTML>
 
 
 
CODEBEHIND
-----------------
 
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
 
namespace KeyotiSearchDemo_CSharp
{
 /// <summary>
 /// Summary description for WebForm1.
 /// </summary>
 public class WebForm1 : System.Web.UI.Page
 {
  protected Keyoti.SearchEngine.Web.SearchBox SearchBox1;
  protected Keyoti.SearchEngine.Web.SearchResult SearchResult1;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // Put user code to initialize the page here
   if(Request.Params["QueryExpr"] == null)
    this.SearchResult1.Visible = false;
  }
 
  #region Web Form Designer generated code
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: This call is required by the ASP.NET Web Form Designer.
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {   
   this.Load += new System.EventHandler(this.Page_Load);
 
  }
  #endregion
 }
}
 

 

Related Questions:

Attachments:

No attachments were found.