I have a Item Form to which I would like to add a redirect feature after submission.

 <button class="btn btn-default" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={https:my-url/Lists/AD_DB/newDisplay.aspx?ID=xxxx}')}" name="btnSave">Save</button>

Is there a way to transfer the Item ID (xxx) to the redirect url?


You can use concat function as below

<button class="btn btn-default" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__commit;__redirect={https:my-url/Lists/AD_DB/newDisplay.aspx?ID=',$ID,'}'))}" name="btnSave">Save</button>

Assuming $ID has the ID value.

| improve this answer | |
  • Perfect, you just missed a ")" after ...$ID,'}')}, I changed to ....$ID,'}'))}. The other thing I did was to change from $ID to @ID and it worked. Thanks! – cubanGuy Nov 6 '14 at 18:22
  • 1
    @cubanGuy I updated the answer. Cheers!! – Amal Hashim Nov 6 '14 at 18:25

If your form is of the same list, here is a little bit nicer solution:

<SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2" RedirectUrl="DispForm.aspx?ID={$ListItemId}"/>

In this case you don't need to specify the url, since it might change.

Don't forget to add the param to the stylesheet:

<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" 
xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
    <xsl:param name="ListItemId"></xsl:param> // <-- do not forget!

    // custom definition of the form

| improve this answer | |

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.