2

I'm creating a custom 'NewForm.aspx' and am looking to customize the 'cancel' button action.

Preferrably I would like it to 'go back' a step, else to go to a hardcoded URL.

I have tried this solution by adding the following code -

<input type="button" value="Close" name="gobackbutton2" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={/Lists/History/AllItems.aspx}')}" />

But when the person clicks on the 'Close' button, it still requires the user to fill out the required fields. How can that be avoided, and/or how can I trigger a 'back' action?

Using SharePoint 2013 Designer

  • Any possible ideas? :) – Simon May 4 '15 at 8:56
  • 1
    'Why are you committing? You can simply drop the commit and now it should redirect away with no problem. On commit it preforms a check on the form (hence forcing users to enter in data) – Roland Oct 13 '15 at 3:49
2

Have you tried this?

TL;DR version, using jQuery:

$(function() {
  $('input[value=Cancel]').click(function() {history.go(-1);});
});

Or to tackle both Cancel buttons at once:

function redirectCancelButtons(){
    // form Cancel button
    jQuery('input[value=Cancel]').click(function() {history.go(-1);});

    // ribbon Cancel button
    jQuery('#Ribbon.ListForm.Edit.Commit.Cancel-Large').click(function(){history.go(-1);});
}
0

Just use RedirectUrl="your url" like:

<SharePoint:GoBackButton runat="server" ControlMode="New" id="gobackbutton1" RedirectUrl="URL"/>
  • Can you provide some information on RedirectUrl? It'd help other people reading your answer to understand it. – wjervis Dec 15 '16 at 11:46
0

As mentioned by @Drale, there is the possibility to overwrite the standard redirect url using the RedirectUrl attribute. There is no really documentation regarding it, but the class definition may help.

This is my solution (redirecting to the DispForm):

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

In order to have the ListItemId defined it must be specified at the beginning of 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

</stylesheet>

Furthermore, this is possible also with the SaveButton (MS page):

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

IMHO I don't know why this works, since the item does not exists yet snd so ListItemId should be null.

EDIT:
Warning! This method has a problem. When the item is deleted, the system tries to lookup the item, obiously it can't found and the user get to an error page.

Furthermore, lets take this example:

<table>
    <tr>
        <td class="ms-descriptiontext" nowrap="nowrap">
            <SharePoint:CreatedModifiedInfo ControlMode="Edit" runat="server"/>
        </td>
        <td class="ms-toolbar" nowrap="nowrap">
            <SharePoint:SaveButton runat="server" ControlMode="Edit" id="savebutton2" RedirectUrl="DispForm.aspx?ID={$ListItemId}"/>
        </td>
        <td class="ms-toolbar" nowrap="nowrap">
            <SharePoint:GoBackButton runat="server" ControlMode="Edit" id="gobackbutton2" />
        </td>
    </tr>
</table>

In this case the attribute RedirectUrl="DispForm.aspx?ID={$ListItemId}" affects also the GoBackButton...

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.