March 11th, 2012
This little javascript can be used to block the sometimes unwanted autosubmit behaviour of a form when the user presses enter while the textfield is active. (JQuery required)
Usage: <input type=”text” class=”blockautosubmit” id=”email” />
1
2
3
4
5
| $('input.blockautosubmit').keypress(function(e) {
if (e.keyCode == 44 || e.which == 44 || e.keyCode == 13 || e.which == 13) {
return false;
}
}); |
Tags: Form validation, Javascript, Visitor usability
Posted in Other | No Comments »
January 23rd, 2012
Here’s a simple extension method for EPiServer when you need to get the friendly url from an internal url.
Note the last line checking if the Uri is an absoluteUri first. If you try to get the AbsoluteUri if it’s not you will get the following exception:
InvalidOperationException: This operation is not supported for a relative URI. This operation is not supported for a relative URI.
1
2
3
4
5
6
| public static string GetFriendlyURL(this string internalURL)
{
var url = new UrlBuilder(internalURL);
EPiServer.Global.UrlRewriteProvider.ConvertToExternal(url, null, System.Text.UTF8Encoding.UTF8);
return url.Uri.IsAbsoluteUri ? url.Uri.AbsoluteUri : url.Uri.OriginalString;
} |
Tags: EPiServer, Extension methods
Posted in EPiServer, EPiServer CMS | 2 Comments »
January 3rd, 2012
In EpiServer you might sometimes need to get PageData, preferably typed, from a page guid.
Here is a simple method for getting a page only by sending a guid as an argument, which we can do thanks to the PermanentPageLinkMap class, and results of other pagetypes than the requested are ignored, as well as any permanent links which are file links.
1
2
3
4
5
6
7
8
9
10
11
12
13
| public static T GetPage<T>(Guid pageGuid) where T : PageData
{
var linkMap = EPiServer.Web.PermanentLinkMapStore.Find(pageGuid) as PermanentPageLinkMap;
if (linkMap != null)
{
var page = DataFactory.Instance.GetPage(linkMap.PageReference);
if (page != null && page is T)
{
return (T)page;
}
}
return null;
} |
Tested in EPiServer CMS 6, but should work fine in version 5 as well.
Tags: EPiServer
Posted in EPiServer, EPiServer CMS | No Comments »
December 16th, 2011
If you have an iframe with external content (aka poor mans integration) you might need to modify the size of the iframe dynamically. Security limitations on javascript can make this a little bit troublesome.
Here is a small how-to if you need to take over the screen from a link inside an iframe, as long as you’re using the same domain name on both the parent and the iframe page. The script below requires jQuery, but should be easy to rewrite if you use any other javascript framework.
Parent page:
1
2
3
4
5
6
7
8
| document.domain = "yourdomainhere.com"; // Only necessary if the subdomain differs from the iframe
resizeFramesetFull = function() {
$("#myiframe").css("position", "absolute");
$("#myiframe").css("top", "0px");
}
resetFrameset = function() {
$("#myiframe").css("position", "relative");
} |
1
| <iframe id="myiframe" name="myiframe" width="100%" marginwidth="0" marginheight="0" frameborder="0"></iframe> |
IFrame page:
1
2
3
| document.domain = "yourdomainhere.com"; // Only necessary if the subdomain differs from the parent
resizeFramesetFull = function() { if (typeof parent.resizeFramesetFull == 'function') parent.resizeFramesetFull();
resetFrameset = function() { if (typeof parent.resetFrameset == 'function') parent.resetFrameset(); } |
1
2
| <a href="javascript:void(0)" onclick="resizeFramesetFull()">FULL SCREEN</a><br />
<a href="javascript:void(0)" onclick="resetFrameset()">RESET IFRAME SIZE</a> |
Tags: Javascript
Posted in Other | No Comments »
September 29th, 2011
Here is just a few examples of how to create and modify pages in EPiServer CMS 5/6 when you are using PageTypeBuilder.
Create new page:
1
2
3
4
5
6
7
8
| PageReference targetContainer = PageReference.StartPage;
MyPageType newPage = (MyPageType)DataFactory.Instance.GetDefaultPageData(targetContainer, PageTypeResolver.Instance.GetPageTypeID(typeof(MyPageType)).Value);
newPage.PageName = "This is the title";
newPage.MyProperty = "Lorem ipsum";
newPage.Category.Add(categoryId);
DataFactory.Instance.Save(newPage, EPiServer.DataAccess.SaveAction.Publish); |
Modify existing page:
1
2
3
4
5
6
| MyPageType clone = myPage.CreateWritableClone() as MyPageType;
// Modify properties
clone.LatestNewsletterDateTime = DateTime.Now;
DataFactory.Instance.Save(clone, SaveAction.Publish | SaveAction.ForceCurrentVersion, AccessLevel.NoAccess); |
Tags: EPiServer, EpiServer Tips & tricks, PageTypeBuilder
Posted in EPiServer, EPiServer CMS | 2 Comments »
May 4th, 2011
I suddenly got this error message when trying to debug in VS 2008:
“Unable to start debugging on the web server.The Microsoft Visual Studio Remote Debugging Monitor has been closed on the remote machine.”
The debugging had worked fine until this point, and I hadn’t changed any code, configuration, database values, or underwear.
What solved it was… wait for it… restarting the browser. I don’t care enough to find out why, but I felt this secret has to come out.
Tags: Debugging, Visual Studio
Posted in Other | No Comments »
May 2nd, 2011
If the right click context menu is missing in EPiServer CMS, the reason might not be obvious. First of all you should check if the context menu javascript is visible in the html source code, which should include something like this: var menu1 = new ContextMenu();
If the javascript of the context menu is visible, the problem could be:
- There is a javascript error on your page. Debug your javascript and fix the problem, or begin by removing all of your javascript to see if the context menu appears.
- You’re using a browser which doesn’t support it.
If you don’t see the javascript, the possible reason could be:
- You don’t have sufficient rights to see the rightmenu. If this is the cause, you will most likely not be able to access edit mode by manually entering the address either.
- It is disabled in admin mode, check setting by going to Admin -> Config tab -> Plug-in Manager -> EPiServer -> Overview tab -> Page Extensions section -> ContextMenu checkbox
- You are missing the form tag in your page. Add <form runat=server>.
- You are using an Enterprise version of EPiServer, and have a bad configuration in either episerver.config or EPiServerFramework.config.
Check the siteHosts settings in both files; the language setting should not differ, nor should it be specified in only one of the config files. See correct example below.
EpiServerFramework.config: <siteHosts siteId=”MySite”><add name=”mysite.local.com” language=”en” /></siteHosts>
episerver.config: <siteHosts><add name=”mysite.local.com” language=”en” /></siteHosts>
Tags: EPiServer, EPiServer configuration, EPiServer Enterprise
Posted in EPiServer, EPiServer CMS | 4 Comments »
March 18th, 2011
Yesterday I noticed very odd behaviour in an editor interface using a javascript showModalDialog function.
Read the rest of this entry »
Tags: Javascript
Posted in Other | 1 Comment »
March 18th, 2011
If you have a custom membership provider connected to an Active Directory and a full user search is made in EPiServer admin mode, the AD can stop connecting with the user running the website. The error generated is “Unknown error (0×80005000)” and the solution is to disable full searches for users in the custom membership provider. If the AD has started to block the connections the IIS seems to need a restart (or at least the website need to restart) in order for the AD connection to start working properly again.
Tags: Active Directory, EPiServer
Posted in EPiServer, EPiServer CMS | No Comments »
February 18th, 2011
Some EPiServer developers still create their own custom property for the only purpose of having a simple dropdown (aka combobox / select list) for editors to choose from a predefined list.
If you only need a simple key/value dropdown, there’s no need to create a custom property – all you need is to configure it using appSettings in web.config. Read the rest of this entry »
Tags: Custom property, EPiServer, EpiServer Tips & tricks, PageTypeBuilder
Posted in EPiServer, EPiServer CMS | 4 Comments »