Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top