Add a redirect on a custom newitem form after you hit the "SharePoint:SaveButton"

At a client, I am building a custom formin SharePoint via a custom newform. One of the requests was that after the form is submitted, users have to be redirected to a “thank you” page.
If you insert a dataview, you get a normal “input type=button” which you can customize like I described here.

With a new item form, we have another button, the SharePoint:SaveButton.
SharePoint gives you this:

<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton2"/>

No onclick event here that we can use.
So, my first guess was to add a &Source parameter in my querystring:

https://myserver/sites/site/SitePages/customnewform.aspx?source=/sites/site/SitePages/thankyou.aspx

That works well, but if I click the Cancel button, I also get redirected to the thank you page. That is something we obviously don’t want.
We can, ofcourse, just delete that Cancel button and get ourselves a custom button with a redirect on it.

While pondering on the button in SharePoint Designer my eye fell on the button properties, which has a RedirectUrl property!!
Select the button, open the properties of that button and locate the RedirectUrl. Give in your own redirect and when you look at the code, a redirectUrl has been added.

<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton2" Text="Send" RedirectUrl="/sites/site/SitePages/thankyou.aspx"/>

Test it out!!
Unfortunately..That does not work in SharePoint 2010 !!!!!!
Don’t know why the option is still there.. I guess it is the same thing as the toolbar (that is on the page, but hidden..).

So, as a workaround, just replace that SharePoint:SaveButton with a input type=”button” !

<input type="button" value="OK" name="btnFormAction" onclick="javascript: {ddwrt:
GenFireServerEvent('__commit;__redirect={/sites/site/SitePages/thankyou.aspx}')}" />

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


5 thoughts on “Add a redirect on a custom newitem form after you hit the "SharePoint:SaveButton"”

  1. Thank you so much! I was researching for this redirect thing on savebutton in SP 2010 past 3 days.

  2. This didn’t work for me. It redirects me to the proper page, however the item isn’t created in the SP list associated with the form.

    1. Make sure you keep the ‘__commit’ part in your code! That is the piece that is used to save the actual item.

  3. I use this also, problem is that when an item is created with a non-unique value in field with forced unique on, the item is not saved, but we still get redirected to the ‘thank you’ page and don’t get the message that our value already exists. Does anyone have a solution for this?

Leave a Reply

Your email address will not be published. Required fields are marked *