Passing a Source Parameter on the Query String with Multiple Other Parameters
I’ve posted on similar tricks to this in the past, but this little trick is really helpful and worth calling out on its own. Say that you’d like to pass a Source parameter on the query String, as SharePoint often does for you:
http://servername/sites/sitename/Lists/MyList/EditForm.aspx?ID=275&Source=http://servername/sites/sitename/default.aspx
Simple, and you see it all the time as you navigate around in SharePoint. In many cases, you’d also like to pass additional parameters that will “travel along” with the Source parameter. The trick for this is to simply encode the ampersand (&) character so that it won’t be treated as the start of a new Query String parameter, but instead just a part of the Source parameter. The ASCII value for the ampersand is 26 in hex, so you encode it as %26 in the URL:
http://servername/sites/sitename/Lists/MyList/EditForm.aspx?ID=275&Source=/sites/sitename/default.aspx?ProjectID=123%26Boolean=0%26EmployeeID=345
Note that I’m passing in the relative URL for the default.aspx page. Get into the habit of using relative URLs all the time and you’ll be in much better shape in general.
With the above URL, when you are finished with the EditForm.aspx page, whether by clicking OK or Cancel, you’ll be redirected to:
http://servername/sites/sitename/default.aspx?ProjectID=123&Boolean=0&EmployeeID=345
hI -,
I’m newbie in SP.. I tried to pass the ID from the source page to target page using the parameter passing.. but no luck on this. Please help.
Thanks in advance.
vanezasuba18:
You haven’t given me anything to go on, really. I’d suggest that you post more details and your code to one of the SharePoint forums out there. Feel free to ping me back with the link.
M.
Mark,
I am trying to connect two elements on a display page and the only example I have is one that show how to do it with the parm ID (Query String). My problem is that I reload this list daily so the ID could be different each day so I wants to link the two on a field called User ID instead. Can this be done and how is that done with regards to parameter source.
In the data view parameters what would I select under parameter source?
Control
Cookie
Form
Query String
Server Variable
What do I specify in the next line?
@Title <— this is the xpath variable name for User ID in the first
Matt:
I’m not sure. If it’s a DispForm, then the ID of the current item is always on the Query String. If the two sources are related, you ought to be able to use that ID as the “anchor” to find the related content in the second DataSource.
M.
Do you have any suggestions for places where I can read up on connecting/relating the two lists for use on the form.
Thanks
Matt:
I’m not sure I’ve ever seen the details all spelled out, but I do it all the time. The DVWP below is from the bottom of an EditForm in one of my demos. It grabs the ID from the Query String and traverses to the related child items in a second list. Hopefully this will give you enough to go on.
M.
Yes that is the problem, I have done it with the ID before because it is passed in the query string but what I am saying is that in this particular app the ID field will not be stable because that file will get replaced everynight with new data (not updated). The User ID field which is actually in list one field Title is the fields that I want to tie list one with elements from list two so badically if list1(Title) = list 2(User ID)
Okay perhaps I am confused…
Two Lists (for now, will be three)
List 1 – lots of fields but the key is a field called User ID whos xpath = /dsQueryResponse/SFDC_User_Management/Rows/Row/@Title
List 2 – Less fields but it also has a field called User ID whos xpath = /dsQueryResponse/SFDC_Hierarchies/Rows/Row/@User_x0020_ID
In List 1 there can only be one record with the same User ID or (@Title)
I have a DispForm_Custom.aspx which is the display from allitems.aspx when an item is selected. On the bottom of this form I am trying to show all the items from List 2 where List 1-User ID equals List 2-User ID
I will also be doing the same for a new list 3 soon also
Matt:
The example I posted is basically what you outline. Navigation SubAreas has child items in Navigation Items. I grab the ID of the Navigation SubArea from the Query String, look up that item, and then match on the @Navigation_x0020_SubArea value. In your case, it’ll be the UserID. The key line is this one:
You can ignore the monkeying arounds with ampersands; I had to do that to get a match when the values contains an ampersand.
M.
Not much of a code guy, have been doing this from SPD Gui, where in the code am I looking for this? First List or the Second one?
Matt:
This is definitely going to require some manual coding on your part. It’s a little hard to tell you exactly what to do, but the DVWP example shows you the general method.
M.
The solution for replacing & char with %26 is really good one .Thanks a Lot Marc
?Source={Source} will allow you to return back to the originating page
Thanks Mark! Brilliant help
Hi,
When we are adding a item to a List, it has to add an item to list and has to open new page, how we can achieve this one.
Thanks