none
Retain form selections when redirected to search results page

    Question

  •  

    Hello,

    I have an aspx page on my SharePoint page that gives users a customised search page.

    The page consists of a  form and the Search core results web part.

    Users fills in text entries and uses drop down menus to create their search query. These are a mixture of HTML text boxes and asp.net drop down menus that are databound to various lists in my site. The form elements have been added directly to the page.

    When the user presses the search button the search options are constructed into a query string URL using JavaScript and the user is redirected to the page they are on at the moment but with their search results.

    This all works brilliantly.

    What I want to do though is retain the users search options between searches. As I am redirecting users to what is technically a different page (http://mydomain/mysite/pages/mysearchpage.aspx to http://mydomain/mysite/pages/mysearchpage.aspx?s=docs&k=hello&k=AnotherTerm:Term1 for example) I am struggling to use cookies as the query string part seems to stop my cookies from being remembered.

    Any help would be great; I don’t have access to the server or Visual studio so everything has to be done client side through scripts ideally.

    Wednesday, February 15, 2012 5:48 PM

Answers

  • Hi EmmaCat

    The best way is use cookie to Store your data. Also you can use javascript call the webservice to Store the data, or use javascript I/O operation to Store the data. Following are some functions about operating the cookie use javascript:

    <script type="text/javascript" language="javascript">

    var name=name1;

    var value= document.getElementById(yourelementid).value;

    SetCookie(name, value);

        functionSetCookie(name, value)//cookie name,cookie value

        {

            varDays = 30; //you can customize it

            varexp = newDate();    //new Date("December 31, 9998");

            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);

            document.cookie = name + "="+ escape(value) + ";expires="+ exp.toGMTString();

        }

        functiongetCookie(name)//get cookies       

        {

            vararr = document.cookie.match(newRegExp("(^| )"+ name + "=([^;]*)(;|$)"));

            if(arr != null) returnunescape(arr[2]); returnnull;

        }

        functiondelCookie(name)//delete cookie

        {

            varexp = newDate();

            exp.setTime(exp.getTime() - 1);

            varcval = getCookie(name);

            if(cval != null) document.cookie = name + "="+ cval + ";expires="+ exp.toGMTString();

        }

    </script>

    javascript call webservice: http://www.hendricksongroup.com/code_call_web_service_javascript.aspx

    jquery call webservice: http://vincenthomedev.wordpress.com/2009/02/10/consuming-an-aspnet-web-service-or-page-method-using-jquery/

    javascript I/O operation: http://crmstuff.blogspot.com/2007/11/how-to-read-write-files-using.html

    Thanks,

    Lhan Han

    Friday, February 17, 2012 10:16 AM
    Moderator
  • Hi EmmaCat

    Yes, use webservice to store the data will make it more robust.

    Thanks,

    Lhan Han

    Sunday, February 19, 2012 12:57 PM
    Moderator

All replies

  • Hi EmmaCat

    The best way is use cookie to Store your data. Also you can use javascript call the webservice to Store the data, or use javascript I/O operation to Store the data. Following are some functions about operating the cookie use javascript:

    <script type="text/javascript" language="javascript">

    var name=name1;

    var value= document.getElementById(yourelementid).value;

    SetCookie(name, value);

        functionSetCookie(name, value)//cookie name,cookie value

        {

            varDays = 30; //you can customize it

            varexp = newDate();    //new Date("December 31, 9998");

            exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);

            document.cookie = name + "="+ escape(value) + ";expires="+ exp.toGMTString();

        }

        functiongetCookie(name)//get cookies       

        {

            vararr = document.cookie.match(newRegExp("(^| )"+ name + "=([^;]*)(;|$)"));

            if(arr != null) returnunescape(arr[2]); returnnull;

        }

        functiondelCookie(name)//delete cookie

        {

            varexp = newDate();

            exp.setTime(exp.getTime() - 1);

            varcval = getCookie(name);

            if(cval != null) document.cookie = name + "="+ cval + ";expires="+ exp.toGMTString();

        }

    </script>

    javascript call webservice: http://www.hendricksongroup.com/code_call_web_service_javascript.aspx

    jquery call webservice: http://vincenthomedev.wordpress.com/2009/02/10/consuming-an-aspnet-web-service-or-page-method-using-jquery/

    javascript I/O operation: http://crmstuff.blogspot.com/2007/11/how-to-read-write-files-using.html

    Thanks,

    Lhan Han

    Friday, February 17, 2012 10:16 AM
    Moderator
  • Thanks for the response.

    I've tried using cookies but the page seems to forget the cookies once the query string has been added to the end of the URL. Does using a webservice to store the data make it more robust?

    Thanks in advance.  

    Friday, February 17, 2012 11:06 AM
  • Hi EmmaCat

    Yes, use webservice to store the data will make it more robust.

    Thanks,

    Lhan Han

    Sunday, February 19, 2012 12:57 PM
    Moderator