TIP: Create „edit this page“ link and edit page without accessing administrative area

December 17, 2007 Digital Experience

In this post I'll explain how to create a functionality that will let you access the edit mode of the page while browsing. I'll also provide you with the code you'll need to implement this.

Basic idea

If you've paid attention to the url while in edit mode of a page, you may have noticed that the url is exactly the same as the url of page when it's not in edit mode, with one important exception. Namely, querystring „cmspagemode=edit“ is appended to the url. So, to achieve our desired functionality, we simply need to create a link that will point to page itself and add that querystring at the end.

Implementation

While there is truly many different ways you can do this, we’ll go with the simplest one. We’ll create a user control that will consist only of one HyperLink control. The text of that HyperLink we’ll set to “Edit this page”. In the Page_Load method of that page we’ll set the url of the link to the current url plus the querystring for edit mode.

Also, because we don’t want this link to be visible to anyone browsing our page, we’ll make it visible only to authenticated users with the permission to modify the page in question.

And that’s it. While this, I believe, is a neat trick, it’s only a trick. In Sitefinity 4.0 (see roadmap) a robust and streamlined “browse-and-edit” feature will be implemented in Sitefinity.

>> DOWNLOAD “EditThisPage” user control.

The Progress Team