Passing source querystring value which contains multiple querystring Values to an Display, Edit or New list item forms

While working on my most recent project I came across an interesting issue with passing around QueryString values to New, Display and Edit list forms. In my scenario I have a web part which displays certain information to the user. They can then choose to drill down which takes them to another page. From here they can they link to the edit or display forms for a custom list. In order to ensure the users is always able to go backwards at any point I was keeping various parameters in the QueryString, including one for the URL for the pervious page, see below example URL’s at each stage.

First Page

http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

Second Page

http://sharepoint/site/SitePages/PageTwo.aspx?TestParamTwo=1&SourceURL=http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

Third Page(List Form)

http://sharepoint/site/listname/EditForm.aspx?ID=1&Source=http://sharepoint/site/SitePages/PageTwo.aspx?TestParamTwo=1&SourceURL=http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

What I was finding was when I clicked save or cancel on the edit form I was getting returned to the correct page but I was losing the SourceURL parameter hence couldn’t return the user to the first page. After some Googling around I found an article suggesting I should encode the ‘&’, ends up as %26, in the SourceURL parameter being passed to the Edit form. After changing and testing I found this worked like a treat so wanted to share for others and for my self in future. I have included the updated version of the URL’s above.

First Page

http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

Second Page

http://sharepoint/site/SitePages/PageTwo.aspx?TestParamTwo=1&SourceURL=http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

Third Page(List Form)

http://sharepoint/site/listname/EditForm.aspx?ID=1&Source=http://sharepoint/site/SitePages/PageTwo.aspx?TestParamTwo=1%26SourceURL=http://sharepoint/site/SitePages/PageOne.aspx?TestParamOne=1

Advertisements

One Response to Passing source querystring value which contains multiple querystring Values to an Display, Edit or New list item forms

  1. dd says:

    thanks this was very helpful

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 )

Connecting to %s

%d bloggers like this: