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

HKFueyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

f_o_o_k_yCommented:
Hi
Shouldn't you use MasterPageFile  Insted WombatMasterPage or   base.OnPreInit(e); before setting it?


Based on article: http://odetocode.com/code/450.aspx

If we attempt to view this content page in design view, Visual Studio will produce the error message shown earlier. If we really want to use the designer with our content page, we can leave the MasterPageFile attribute empty, like in the following code:

<%@ Page Language="VB" MasterPageFile=""  %>
<asp:Content ID="Content1" ContentPlaceHolderID="NestedContent" Runat="Server">
</asp:Content>
We can’t just drop the MasterPageFile attribute from the @ Page directive, because the designer will raise a different error (“Content controls are allowed only in content page that references a master page”). The empty attribute appears to trick the designer into allowing us into design mode.

At runtime, however, the page will throw an exception because it doesn’t have a master file. We can avoid the exception by programmatically setting the MasterPageFile property at runtime. We know we will need to set the master page before or during the PreInit event. The following code reads the masterPageFile attribute from the <pages> section of web.config. By putting the code into a base class, we can cover all the content pages in an application.

using System;
using System.Web.UI;
using System.Web.Configuration;
using System.Configuration;

public class BaseContentPage : Page
{
    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        PagesSection pagesConfig =
             ConfigurationManager.GetSection("system.web/pages")
                 as PagesSection;

        MasterPageFile = pagesConfig.MasterPageFile;
    }
}




0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HKFueyAuthor Commented:
Hi FOOKY, thanks for the detailed response
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.