Redirect to custom page on OK or Cancel click in Newform.aspx sharepoint

In many cases you want to redirect the user to some custom page from newForm.aspx after adding an item ie "Ok" click or "Cancel" click. You can do that easily..

After creating a Custom Form in designer remove or hide the Ok and Cancel button and place this code instead.

<input type=”button” value="Submit” name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(‘__commit;__redirect={userView.aspx}’)}" />

For the _redirect field give the custon page name you want to redirect to.
__commit in this statement will save the form details in to the list.

Similarly for cancel button add the below code.

<input type="button" value="Cancel" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={userView.aspx}')}" />


11 thoughts on “Redirect to custom page on OK or Cancel click in Newform.aspx sharepoint

Add yours

  1. Does your website have a contact page? I’m having trouble locating it but, I’d like to send you
    an email. I’ve got some recommendations for your blog you might be interested in hearing. Either way, great site and I look forward to seeing it expand over time.

  2. Hello my family member! I want to say that
    this article is amazing, nice written and come with almost
    all important infos. I’d like to see extra posts like this .

  3. This code is great. I’m using it on a new form entry page. When the user clicks save, I want to redirect it to the same record on another edit form. So basically, I want to set the url to something like this: <input type="button" value="OK" name="btnFormAction" onclick="javascript: {ddwrt:GenFireServerEvent(' __commit ;__redirect={/Lists/WorkOrder/AddPartsOnSave.aspx?ID=xxx. Where the xxx is the same record I was just on but on a different form. Is this possible?

    1. This might help some one now: Best way to redirect user from new form to edit form is use SPServices, there is function on SPServices that just do this.

  4. Hi i am using sharepoint 2013… this work on default newform.aspx page….if yes..pls tell me how can i use this sharepoint 2013 deisgner because i didn’t see any button script in newform.aspx…..pleas ehelp me

  5. naturally like your website however you need to test the spelling
    on quite a few of your posts. A number of them are rife with spelling problems and I in finding it
    very bothersome to tell the reality however I’ll surely
    come back again.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a website or blog at

Up ↑

%d bloggers like this: