How do I make a custom publish button for a page and make it do the same as the ribbon publish button? We have a request from the customer to make a simple page that should have a custom publish button in addition to the publish button in the Ribbon (see picture). I have searched google and tried, but could not find any solution to this.

A possible solution could involve the SPContext.Current.File.Publish("myComment"); but this demands a lot of custom handling if there is a workflow?

Publishing button

2 Answers 2

ExecuteOrDelayUntilScriptLoaded(function () {
        var pageStateGroupPublishValue = SP.Ribbon.PageState.PageStateCommands.pageStateGroupSubmitForApproval;
        SP.Ribbon.PageManager.get_instance().executeRootCommand(pageStateGroupPublishValue, window.g_CUIcommandProperties, { CommandId: pageStateGroupPublishValue }, null);
    }, "sp.ribbon.js");

@Andrey Markeev, Looks like window.g_CUIcommandProperties is undefined on some pages. This code worked for me:

<script type="text/javascript">
    function Custom_Submit(command)
        SP.Ribbon.PageState.Handlers.showStateChangeDialog(command, SP.Ribbon.PageState.ImportedNativeData.CommandHandlers[command]);
<input type="button" onclick="javascript:Custom_Submit('PageStateGroupPublish'); return false;" value="Publish" id="btnPublish"></input>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.