SearchBox.cs :  » Bloggers » BlogEngine.NET » Controls » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Bloggers » BlogEngine.NET 
BlogEngine.NET » Controls » SearchBox.cs
#region Using

using System;
using System.Web;
using System.Web.UI;
using System.Text;
using BlogEngine.Core;

#endregion

namespace Controls{
  /// <summary>
  /// Includes a reference to a JavaScript.
  /// <remarks>
  /// This control is needed in order to let the src
  /// attribute of the script tage be relative to the root.
  /// </remarks>
  /// </summary>
  public class SearchBox : Control
  {

    static SearchBox()
    {
      BlogSettings.Changed += delegate { _Html = null; };
      //Post.Saved += delegate { _Html = null; };
    }

    private static object _SyncRoot = new object();

    private static string _Html;
    /// <summary>
    /// Gets the HTML to render.
    /// </summary>
    private string Html
    {
      get
      {
        lock (_SyncRoot)
        {
          BuildHtml();
        }

        return _Html;
      }
    }

    private void BuildHtml()
    {
      string text = Context.Request.QueryString["q"] != null ? HttpUtility.HtmlEncode(Context.Request.QueryString["q"]) : BlogSettings.Instance.SearchDefaultText;
      StringBuilder sb = new StringBuilder();
      sb.AppendLine("<div id=\"searchbox\">");
      sb.Append("<label for=\"searchfield\" style=\"display:none\">Search</label>");
      sb.AppendFormat("<input type=\"text\" value=\"{0}\" id=\"searchfield\" onkeypress=\"if(event.keyCode==13) return BlogEngine.search('{1}')\" onfocus=\"BlogEngine.searchClear('{2}')\" onblur=\"BlogEngine.searchClear('{2}')\" />", text, Utils.RelativeWebRoot, text);
      sb.AppendFormat("<input type=\"button\" value=\"{0}\" id=\"searchbutton\" onclick=\"BlogEngine.search('{1}');\" onkeypress=\"BlogEngine.search('{1}');\" />", BlogSettings.Instance.SearchButtonText, Utils.RelativeWebRoot);

      if (BlogSettings.Instance.EnableCommentSearch)
      {
        string check = Context.Request.QueryString["comment"] != null ? "checked=\"checked\"" : string.Empty;
        sb.AppendFormat("<br /><input type=\"checkbox\" id=\"searchcomments\" {0} />", check);
        if (!string.IsNullOrEmpty(BlogSettings.Instance.SearchCommentLabelText))
          sb.AppendFormat("<label for=\"searchcomments\">{0}</label>", BlogSettings.Instance.SearchCommentLabelText);
      }

      sb.AppendLine("</div>");
      _Html = sb.ToString();
    }

    /// <summary>
    /// Renders the control as a script tag.
    /// </summary>
    public override void RenderControl(HtmlTextWriter writer)
    {
      writer.Write(Html);
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.