I have a need to throw down a link in the right side bar of my page that will allow the user to put the page into edit mode. The edit page link in the site actions menu seems to do a postback to get the page into edit mode. My question is how can I put the current page into mode, or obtain a link that will have the same effect?
I don't think you can put the page in edit mode by just clicking a link and without causing a server trip because the page needs to be checked out before it can be put in edit mode.
If you append following to current page url, page can be put in edit mode with a server trip and it might give a message if page is not checked out:
?ControlMode=edit&DisplayMode=design
UPDATE Based on Comments
How about using out of the box control which displays Edit button link when page is in display mode and save button when the page is in edit button. Using this you dont have to worry about checking states, permissions, display/hide etc.
<SharePoint:PageStateActionButton ID="PageStateActionButton" runat="server" Visible="false" />
Problem solved. Here was the solution I ended up using.
<a id="editPageLink" runat="server" href="javascript:switchToAuthoringMode();" class="edititem"><label></label>edit this page</a>
<script type="text/javascript">
function switchToAuthoringMode() {
if (document.forms['aspnetForm']['MSOLayout_InDesignMode'] != null)
document.forms['aspnetForm']['MSOLayout_InDesignMode'].value = 1;
if (document.forms['aspnetForm']['MSOAuthoringConsole_FormContext'] != null)
document.forms['aspnetForm']['MSOAuthoringConsole_FormContext'].value = 1;
if (document.forms['aspnetForm']['MSOSPWebPartManager_DisplayModeName'] != null)
document.forms['aspnetForm']['MSOSPWebPartManager_DisplayModeName'].value = 'Design';
<%= Page.ClientScript.GetPostBackEventReference(editPageLink, "EditCommunityPage", true) %>
}
</script>