Redirect on save of EditForm.aspx to DispForm.aspx with ID querystring parameter passed back to DispForm.aspx
-
Friday, June 22, 2012 2:56 PM
I have replaced the standard display of a dispForm.aspx form for a particular list with two custom webparts.
General steps involved.
1. Hide standard/default display on dispForm.aspx
2. Created and added custom webpart to dispForm.aspx based on customer's criteria. (Ex. Display's Company data)
3. Created and added custom webpart to display a SPGridView to display child data of parent information from step 2 above. This gridview has an edit button per row which takes the user to the editForm.aspx for the address they want to modify. (Ex. Display's all addresses for a particular company)
The issue I am running into is after they update the address it takes them to the allitem.aspx of the address list and what I want is for it to take them back to the dispForm.aspx for the customer record they were on.
I found several links that post javascript code to for use in a Content Editor Web Part (CEWP) for the use of $("#aspnetForm").attr('action',newAction); as well as the code for the cancel button. Of course the cancel button work fine, not a problem there. My problem is I want to send not only the source in but the ID in as well on the querystring. I can do this just fine (it is being passed to the save event) but I don't know what is happening in the save event becuase when I get back to my dispForm I don't have querystring variables available to the page. So, basically I can use the &Source to get me back to the correct dispForm.apsx, but when I check the querystring collection there isn't anything availabe in it.
I know this must be possible. How can I get back to the same exact dispForm.apsx record after editing data in a SPGridView?
I created the web parts using VS2010, and javascript to add the redirect to the editForm.aspx page to get be back to the dispForm.aspx.
Any help or direction would be appreciated.
Thanks,
All Replies
-
Friday, June 22, 2012 5:05 PMWhen using the Source query string make sure that you urlencode the link that you have as the value. The '&' and '?' characters that you intend to be query parameters for the url that is the value of Source, if not properly encoded, will result in those query parameters being added to the current url.
-
Friday, June 22, 2012 6:31 PMI have encoded the URL before passing it to my function setOnSubmitRedi
function setOnSubmitRedir(redirURL)
var action = $("#aspnetForm").attr('action');
var end = action.indexOf('&');
if(action.indexOf('&')<0){
newAction = action + "?Source=" + redirURL;
}else{
newAction = action.substring(0,end) + "&Source=" + redirURL;
}alert(newAction); // see that it is encoded
$("#aspnetForm").attr('action',newAction );}
The page is saved and I am redirected back to dispForm.aspx but the query string collection does not contain any data.
Should I be using something else to save the editForm and redirect back to dispForm?
-
Friday, June 22, 2012 7:12 PMSorry, but I don't see where you encoded 'redirURL' there. Could you provide an example of what's in the alert box? That would tell me if it's even a problem.
-
Friday, June 22, 2012 7:47 PM
Here is what is in the newAction, which is being passed back to DispForm.aspx based on Source=. I am just not getting any query string when I get to VS2010 dsipForm to pull the ID out to show the correct record.
-
Monday, June 25, 2012 7:45 AMModerator
Hi speedbwild,
For this issue, you can get the item id through url of editform page, which can be get using window.location, then generate the displayform url as source url of the editform page, here is an example about this, for more information, see:
http://sharepointjavascript.wordpress.com/2011/04/23/redirect-from-newform-to-dispform-or-editform/You can also try to modify editform page to achieve this, for more information, please refer to:
http://vishalmarnepune.blogspot.com/2011/11/how-to-redirect-from-custom-edit-form.htmlThanks,
QiaoQiao Wei
TechNet Community Support
-
Monday, June 25, 2012 11:58 AM
Qiao,<o:p></o:p>
Thank you for
the links, but I don't think they will work for what I am trying to do. I want
to go from dispForm list A to editForm list B and then back to dispForm list A.
Basically I have a dispForm (list A) that has a SharePoint grid view add to it.
The grid contains data from a totally different list (list B). The grid has an
edit button where the user can edit the items in list B. There is a
relationship between list A and list B, but they are totally different list. If
a user click on the grid to edit an item in list B I want them to return back
to where they were (dispForm for list A) when they are done with the edit (on
save or on cancel). I do not want them to return to the allitems list for list
B (which is the default SharePoint behavior). <o:p></o:p>Since I am
going from an editForm of one list to a dispForm of another I need to be able
to pass in a query parameter for the original dispForm ID. Form the dispform on
click of the edit icon in the grid view; I am able to get to the editform of
list B. I pass on the query string the ID of list A so I know which item I want
to go back to. Servy42, suggested that I encode the URL, so that on save the additional
query parameters are passed with the source parameter. I also found other post
suggesting the same thing, but I can't seem to get that to work. See query
string above, the data displayed in what I am sending over in the NewAction
variable below. $("#aspnetForm").attr('action',newAction ); <o:p></o:p>Once I get
back to the dispForm (which I am able to do) I need to read the ID querystring
parameter to get the ID for the record I want to display. This I am not able to
do. Currently the querystring collection is empty.Any ideas or suggestions would be appreciated.<o:p></o:p>
-
Monday, June 25, 2012 5:30 PM
Thank you for your help. I figured out what my issue was. In my dispForm.aspx I am passing several parameters in my editform.aspx. When I created my Content Editor Web Part (CEWP) I was reading in my parameters and storing them to use on save of the edit form. My issue was I had two 'source' parameters, the one I passed in from my dispForm and then one I appended on inside of my CEWP. I removed all the code associated with my onSave of the edit page and let it function based on the redirect parameters and everything worked as expected.
Thank you all very much.
- Proposed As Answer by servy42Microsoft Community Contributor Monday, June 25, 2012 6:05 PM
- Marked As Answer by Qiao WeiMicrosoft Contingent Staff, Moderator Tuesday, June 26, 2012 1:43 AM

