Using a Query String parameter in the Search Results Web Part

Further work on fixing a colleague’s code. Like some of the posts I’ve found, he seems to have thought that to get the query string parameter he’d have to use Javascript – something like this. However, I found myself thinking of the Data View web part – it allows parameters based on the query string. Most people know about that. What I found, and what I think some folks don’t realise, is that the Search Core Results Web Part allows you to have query string parameters too…

Don’t believe me? Open SharePoint Designer, and go to the properties of the Search Core Results Web Part:

Search Web Part Properties in SharePoint Designer

Look – it has parameters:

Parameters Dialog in SharePoint Designer

And you can see these in the code – in just the same structure as the Dataview WebPart:

Code supporting parameters in SharePoint Designer.

Then you can use the query string value (which I’ve called query) like so:

<xsl:value-of select="&query" />

And I’ll explain why I’ve been going through all this in my next post…

Advertisements
Using a Query String parameter in the Search Results Web Part

4 thoughts on “Using a Query String parameter in the Search Results Web Part

  1. Raymond says:

    Hi Andy,
    What exactly are the steps to be able to grab the Querystring from the Search Results webpart? I’ve tried editing the results.aspx page of my SearchCenter from Sharepoint Designer and it directs me to the _catalogsmasterpagesearchresults.aspx file.

    Is this the correct file to edit to be able to add the parameters? I tried adding a parameter from that page and it just resets to an empty Parameters list. What gives?

    Thanks in advance and hope you can provide help as I need to implement your PDF highlighting solution.

  2. Hi Raymond,

    Ah, right. That’s happening ‘cos your page is attached to a page layout. Various options. The easiest is:

    – Go to Search Center > Pages.
    – Create a new ‘Page’. Give it a title, and choose a page layout of ‘(Welcome Page) Search Results Page’
    – Open SharePoint Designer. Browser to your Search Center > Pages library.
    – Right click on your new page
    – Select ‘Detach from Page Layout’
    – Now double click on it to open it for editting.

    You’ll now be editting your own stand-alone copy of the page, rather than the page layout.

    Of course, you could detach the results.aspx page itself, but I like to leave the out-of-box pages there.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s