2

I have successfully created a feature in sharepoint that modifies the existing edit dialog and adds a custom button to it like this.

Modified sharepoint dialog

and I am aware that I can pass back data when the user clicks the custom button like this.

<CommandUIHandlers>
    <CommandUIHandler Command="ActivateUser" CommandAction="/_layouts/MyFeature/MakeUserActive.aspx?ListID={ListId}&amp;ItemID={ItemId}&amp;ItemUrl={ItemUrl}&amp;ListUrlDir={ListUrlDir}" />
</CommandUIHandlers>

As detailed here

I can now handle the list item and perform my required actions on it BUT given that this button has been added in the modify context (IE: Inside the sharepoint edit item dialog) what if you want to save changes to the data itself?

To me it seems like using your custom button would always mean losing any changes the user has made to the data. Is there a way around this?

Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243

1 Answers1

4

Good question!

You actually already linked to the solution: Right now you are simply redirecting the user by using a URL as your CommandAction: CommandAction="/_layouts/MyFeature/MakeUserActive.aspx?ListID={ListId}&amp;ItemID={ItemId}&amp;ItemUrl={ItemUrl}&amp;ListUrlDir={ListUrlDir}"

This if course redirects the user to another page without saving the current entry. What you want to do is use Javascript as linked in the MSDN article:

CommandAction="javascript:alert('here be dragons');"

You can either work the the SharePoint Javascript object model here and use something like SP.ListOperation.Selection.getSelectedItems(); or you could use complete custom code.
From your aspx page name I can see you want to "make a use active" (btw: wouldn't "ActivateUser.aspx" be nicer?). If this simply means setting a property in another list you could do that with the SharePoint OM, if it is some custom stuff you would need a webservice which you can call from JavaScript and "activate the user" like that. You can of course always access the current form and pass on the values the user entered. Or you could create a custom save button which does some stuff (activate user) before saving.

Lastly: You can also have postbacks in your custom button where you could do anything you'd like.

Dennis G
  • 21,405
  • 19
  • 96
  • 133
  • Thank you for your response but unfortunately I'm still left a little confused. For example: I assumed that in my MakeUserActive.aspx (Or as you rightly suggest ActivateUser.aspx) page I would be able to access the form properties through Request.Form but this was empty. Could you elaborate on the postback scenario? – Maxim Gershkovich Jun 15 '12 at 02:27
  • I'm not sure what SharePoint does magically, but Request.Form couldn't be filled because the CommandAction is a JavaScript command - hence all it can do is redirect. The new form can't know about the old form therefore. Just google for ribbon postback and you will find many examples such as this one: http://blog.dennus.net/2010/07/20/ribbon-buttons-with-postback-in-sp2010/ – Dennis G Jun 15 '12 at 05:53
  • Ok that was the keyword I was looking for "ribbon postback". Thank you very much for that. This article explains everything for anyone interested: http://blogs.msdn.com/b/sridhara/archive/2010/12/30/implementing-a-post-back-button-in-a-sharepoint-2010-web-part-with-contextual-ribbon.aspx – Maxim Gershkovich Jun 18 '12 at 23:48