Passing Query String Values as Part of the Source Query String Parameter in SharePoint

SharePoint has a nice capability on many pages where, if you pass a Query String parameter named Source with a value of a page URL, the user is returned to that page when they are done with the activity.  An example would be when a user clicks on an ‘Add new document’ list on a site where they are a contributor.  The current page’s URL is specified as the Source parameter, and when the user is done adding the document, they return to the current page.

There are times when you’re sending your user off from a page that relies on its own Query String values to configure it.  So, how do you pass those values along with the source so that when the user gets back, they see the page configured correctly?  The trick is a little encoding magic.  Configure your URL to look like something like this:

<a href="{concat('/PG/Policy%20Guidance/Forms/DispForm.aspx?ID=', @ID,
         '&Source=', $URL,
         '?Series=', $Series,
         '%26ContentArea=', $ContentArea)
     }">

This will evaluate to something like this URL:

/PG/Policy%20Guidance/Forms/DispForm.aspx?ID=1&Source=/PG/default.aspx/?Series=SeriesValue%26ContentArea=ContentAreaValue

By placing a question mark (?) after the Source URL value and encoding the ampersand (&) between parameter/value pairs as %26, you can ensure that those values are passed back to the Source URL when the user returns to that page.  This will also work if you are building your own forms and are using the ddwrt:GenFireServerEvent(‘__redirectsource;’) function.

Technorati tags: , ,

Similar Posts

9 Comments

  1. Hi Marc, going crazy, thought you could help. I have a dataview document libary on the dispform.aspx. I have a parameter set called ParameterCaseID. Have a link on the doc lib as follows: Upload a new Document for a Case…

    I press Upload a new document, I go to the upload.aspx. Once I load the document (I see the CaseID in the url), it goes to the editform.aspx. I can’t seem to get the parameter to pass to the editform.aspx, then back to the Dispform.aspx. I want the document to be only for the caseid parent.

    Your thoughts on my url mess.

  2. Hi Marc,

    I have custom Newform.aspx and Editform.aspx in which I am using DVWP.

    1) I need to pass value selected in masterpage navigation like year,quarter to newform.aspx as querystring but it redirects me to blank page.

    Also to note here is that I am using concept of Intermediate page to redirect to newform or editform based on ID exist or not for current user.

    so if you could help me out using intermediate page how can I get querystring to be passed would be appreciable.

    Thanks,
    Anjalee

    1. Anjalee:

      It’s sort of impossible for me to tell you the answer on this one. It sounds like you’ve got some code in place on your “intermediate page” which isn’t working properly and you’ll simply need to debug it.

      M.

      1. Hi Marc,

        Thanks for the reply and yes it was issue with the code I was writing and was missing some value to pass…Anyways it has been resolved now…

        Now , I have requirement where in I need to check if for selected year and quarter any item exist for user or not and redirect to Newform.aspx if no item found otherwise redirect to Editform.aspx.

        I was just wondering if you could give some idea about the template or code needs to be write in intermediate page to achieve this would be very grateful…

        Thanks,
        Anjalee

        1. Anjalee:

          It really depends on what you’ve got in that page already and what approach you are taking. You could use jQuery and SPServices to call GetListItems or you could do this with a DVWP.

          M.

          1. Marc,

            I am using approach you described in,

            http://sympmarc.com/2009/06/12/redirect-to-another-page-from-newform-aspx-with-the-new-items-id/

            to open newform.aspx if no ID found otherwise redirect to edit form created by user and also I am passing value to Querystring selected in home page navigation .

            So the next step is I would like to add this additional functionality in same page to check for the value passed if ID found for current user or not…

            Thanks,
            Anjalee

  3. I used it like this in a straight Javascript file to generate url:

    url="/sites/App/ProductSynergy/Lists/ImpactResponse/NewForm.aspx?Topic="+topic+
                                                "&App="+app+"&CurrDate="+DueDate+"&tID="+tID+"&SH="+sh;
                                                    url=url.concat('&Source=','/sites/App/ProductSynergy/SitePages/ResponseInfo.aspx',
                                                         '?Topic=', topic,
                                                         '%26CurrDate=', DueDate,
                                                         '%26tID=', tID,
                                                         '%26mID=', mID,
                                                         '%26docLinks=', docNames);
    
    newForm= ""+"";

Leave a Reply to Anjalee Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.