1

I want to redirect user after editing item and pressing save button to item DispForm. I currently have JS code:

$( document ).ready(function() {
            $('input[value=Save]').click(function() {
                var ur = window.location.assign;
                var URL = ur.replace('EditForm.aspx','DispForm.aspx');
                window.location.assign(URL);  
            });
        });

Problem with this code currently is, that it works time to time.. Which means, it does redirect to DispForm few times and then JS seems to fail load and redirect to default AllItems.

  • me too facing the same issue – dasarp Oct 31 '18 at 9:40
4

You want to override function PreSaveAction() instead of detecting the click with JQuery.

2

In SharePoint instead of $(document).ready you should use _spBodyOnLoadFunctionNames for you this would look like this:

_spBodyOnLoadFunctionNames.push("myCustomFunctionName");
function myCustomFunctionName(){
            $('input[value=Save]').click(function() {
                var ur = window.location.assign;
                var URL = ur.replace('EditForm.aspx','DispForm.aspx');
                window.location.assign(URL);  
            });

}

Reference Link: http://www.stephanrocks.com/2011/10/05/_spbodyonloadfunctionnames-in-sharepoint-vs-jquerys-document-ready/

  • This still doesn't seem to work, I managed to get it redirect me back to DispForm only one time in about 10 tries. Also reading the link, then $ should be replaced with jQuery? – Taurib Apr 13 '15 at 11:39
  • I guess it happens because the "Save" Button is controlled server side and not on client side. It would be better if you would just edit your Form or create a new one manually and create the behaviour you want. It's easy if you use InfoPath. – Gwny Apr 13 '15 at 12:07
0

Another, perhaps easier way, to redirect to a specific page after submission is to add the Source querystring parameter to the current page URL, like this:

http://yoursite/path-to-your-edit-form.aspx?ID=someid&Source=/yoursite/path-to-your-display-form.aspx?ID=someid
  • how to add source querystring parameter in the URL ?, programmatically – dasarp Oct 31 '18 at 9:41
0

As said before... Overwrite the presaveaction() and put something like this in:

newURL = "DispForm.aspx?ID=" + YOUR_FORM_ID_HERE
currentURL = $("form")[0].action;
postbackURL = currentURL.replace(GetUrlKeyValue("Source", true, currentURL), newURL);
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions($('[name$="$diidIOSaveItem"]').attr('name'), "", true, "", postbackURL, false, true));

Havent tested it. You just need to grab the ID of the current Item, but it should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.