4

I have a SharePoint SaveButton in my EditFormTemplate and I don't want the browser to redirect to the default location which is the List View (i.e. AllItems.aspx). I instead want the user to be redirected to another page.

Many other people seem to have the same issue. I do not wish to replace the SharePoint SaveButton with a standard aspx button control and use JavaScript as this presents it's own set of problems and frankly I don't think that this sort of functionality deserves a JavaScript hack.

If an attribute called "RedirectURL" does in fact exist for the SharePoint SaveButton (which it does) then why on Earth would it not simply redirect the browser to the specified URL?

<SharePoint:SaveButton ID="SaveButton1" runat="server" RedirectUrl="[My Custom URL]" />

Why doesn't the code above do what I want it to do?

Ami Schreiber
  • 287
  • 2
  • 6
  • 20

3 Answers3

1

You need to use a JavaScript call ddwrt:GenFireServerEvent('_redirect={URL}'. Take a look at the example below:

<input type="button" class="contact-button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={example.aspx}')}" />

Hope this helps.

  • I was hoping to avoid using JavaScript. Why does the RedirectURL attribute exist then? What purpose does it serve? – Ami Schreiber Mar 26 '14 at 16:34
  • Even if I go with the standard HTML input button route using your sample code above and a JavaScript onclick event it still doesn't work. In fact the button isn't even rendered. Please note that when I use this approach for my Custom Upload ASPX page it works fine. The issue I am having occurs on my EditForm RenderingTemplate. – Ami Schreiber Mar 26 '14 at 17:26
0

OK. I figured it out.

I created a SPListItemEventReceiver and set the ItemUpdated Synchronization element in the Elements.xml file to "Synchronous".

<Synchronization>Synchronous</Synchronization>

I then followed the instructions outlined here.

Since I needed to perform the redirect after an Update I didn't have to do all of the hacky stuff to try and perform an Updated async operation in the Updating async event as described in the link above for ItemAdded and ItemAdding.

I simply added a private HttpContext property called currentContext, added a default constructor where I set the currentContext property to HttpContext.Current and then did the SPUtility.Redirect in my ItemUpdated event using the value stored in the currentContext property that was set in the constructor.

Community
  • 1
  • 1
Ami Schreiber
  • 287
  • 2
  • 6
  • 20
0

I've had problems with the SaveButton if the URL of the form it is used on includes a Source parameter. I don't recall details but my fix was just not to include that parameter when opening the form.

Sounds like a different problem for you, but that may help someone.

Dave

TimTheEnchanter
  • 3,370
  • 1
  • 26
  • 47