Link to home
Start Free TrialLog in
Avatar of HKFuey
HKFueyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Back Slashes break search aspx.cs

If a user searches our web site for a product with more than one slash e.g. 123/456/1
They get this error: -
Server Error in '/' Application.

Content controls are allowed only in content page that references a master page.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: Content controls are allowed only in content page that references a master page.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[HttpException (0x80004005): Content controls are allowed only in content page that references a master page.]
   System.Web.UI.MasterPage.CreateMaster(TemplateControl owner, HttpContext context, VirtualPath masterPageFile, IDictionary contentTemplateCollection) +8672243
   System.Web.UI.Page.get_Master() +51
   System.Web.UI.Page.ApplyMasterPage() +15
   System.Web.UI.Page.PerformPreInit() +45
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +282

I have inserted the code that I think does the search, please be patient as I'm not familiar with this stuff.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class SearchResults : Wombat.Business.Page
{
    protected override void OnPreInit(EventArgs e)
    {
        WombatMasterPage = "content.master";
        base.OnPreInit(e);
    }

    protected string SearchText
    {
        get
        {
            if (ViewState["SearchText"] == null)
                return "";
            else
                return (string)ViewState["SearchText"];
        }
        set
        {
            ViewState["SearchText"] = value;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        ((HtmlHead)this.Master.FindControl("oHead")).Title = "CompanyName - Search";
        if (!IsPostBack)
        {            
            if (Request.QueryString["SearchText"] != null)
            {
                SearchText = Request.QueryString["SearchText"].ToString();
                if(SearchText!=string.Empty)
                    Search();
            }
        }
    }

    private void Search()
    {
        DataTable dtbSearchResults = Business.Search.SearchCompanyName(SearchText);
        repSearchResults.DataSource = dtbSearchResults;
        repSearchResults.DataBind();
        if (repSearchResults.Items.Count == 0)
            repSearchResults.Visible = false;
        else
            repSearchResults.Visible = true;
        lbResults.Text = "You searched for <span style=\"color:red;\">" + SearchText + "</span> and it returned " + repSearchResults.Items.Count.ToString() + " results";
    }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of f_o_o_k_y
f_o_o_k_y
Flag of Poland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HKFuey

ASKER

Hi FOOKY, thanks for the detailed response