<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>C#</title>
        <link>http://blogs.interakting.co.uk/brad/category/31.aspx</link>
        <description>C# is an object-oriented programming language developed by Microsoft as part of the .NET initiative and later approved as a standard by ECMA and ISO.
 Anders Hejlsberg leads development of the C# language, which has a procedural, object-oriented syntax based on C++ and includes aspects of several other programming languages (most notably Delphi and Java) with a particular emphasis on simplification.</description>
        <language>en-GB</language>
        <copyright>Brad</copyright>
        <managingEditor>pbradley@businessdecision.co.uk</managingEditor>
        <generator>Subtext Version 1.9.5.177</generator>
        <item>
            <title>Updating EPiServer Version: Login Failed for User ''</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/08/14/updating-episerver-version-login-failed-for-user.aspx</link>
            <description>&lt;p&gt;I've just spent too long trying to upgrade &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt; CMS 5 to SP2 but kept getting the following error:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Login failed &lt;span style="color: #0000ff"&gt;for&lt;/span&gt; user &lt;span style="color: #006080"&gt;''&lt;/span&gt;. The user &lt;span style="color: #0000ff"&gt;is&lt;/span&gt; not associated with a trusted SQL Server connection.&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Turns out the problem was that EPiServerManager was pulling the connection string out of my web.config, but it appears it was ignoring the fact it specified an Integrated/Windows connection and was passing an empty SQL username to the database - hence the empty quote marks above. (cheers for your help &lt;a href="http://blogs.interakting.co.uk/steve/Default.aspx" target="_blank"&gt;Steve&lt;/a&gt;!)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt; Temporarily change the SQL connection string in the site's web.config to use an SQL username/password, perform the update and change the string back.&lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/337.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/08/14/updating-episerver-version-login-failed-for-user.aspx</guid>
            <pubDate>Thu, 14 Aug 2008 14:27:16 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/337.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/08/14/updating-episerver-version-login-failed-for-user.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/337.aspx</wfw:commentRss>
        </item>
        <item>
            <title>EPiServer: Dynamic SiteMap.xml generator for Google</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/12/EPiServer-Dynamic-SiteMap.xml-generator-for-Google.aspx</link>
            <description>&lt;p&gt;Having stumbled across &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt;'s &lt;a href="http://www.google.com/webmasters/tools" target="_blank"&gt;Webmaster Tools&lt;/a&gt; a while ago it's been in the back of my mind to create a custom HttpHandler to dynamically create a (virtual) SiteMap.xml file that &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; (and other search engines) can use as a reference when spidering my sites.&lt;/p&gt;  &lt;p&gt;I thought I'd share the basic implantation as a starting point. Ideally you'd add a property to each &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt; &lt;em&gt;PageType&lt;/em&gt; page for "change frequency" and "priority" which the sitemap generator would then use, but for this basic version I've simply set the homepage to 1.0 (the maximum priority) with a daily change, and all other pages to 0.6 and weekly.&lt;/p&gt;  &lt;p&gt;First declare the class and the required members:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; SearchEngineSiteMap : IHttpHandler
{
    &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; IHttpHandler.IsReusable
    {
        get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;; }
    }
    &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; IHttpHandler.ProcessRequest(HttpContext context)
    {
        GenerateSiteMap(context);
    }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next we need to configure the output stream, create an XmlTextWriter and the outer Xml block:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Generate the SiteMap&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="context"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; GenerateSiteMap(HttpContext context)
{
    &lt;span style="color: #008000"&gt;//Set the response information&lt;/span&gt;
    context.Response.Expires = -1;
    context.Response.ContentType = &lt;span style="color: #006080"&gt;"application/xml"&lt;/span&gt;;
    Encoding encoding = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UTF8Encoding();
    context.Response.ContentEncoding = encoding;

    &lt;span style="color: #008000"&gt;//Create an XMLTextWriter to build the XML, passing it the context's outputstream&lt;/span&gt;
    XmlTextWriter xmlTextWriter = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlTextWriter(context.Response.OutputStream, encoding);
    xmlTextWriter.Formatting = Formatting.Indented;
    xmlTextWriter.WriteStartDocument();

    &lt;span style="color: #008000"&gt;//Write the root xml element&lt;/span&gt;
    xmlTextWriter.WriteStartElement(&lt;span style="color: #006080"&gt;"urlset"&lt;/span&gt;);
    xmlTextWriter.WriteStartAttribute(&lt;span style="color: #006080"&gt;"xmlns"&lt;/span&gt;);
    xmlTextWriter.WriteValue(&lt;span style="color: #006080"&gt;"http://www.sitemaps.org/schemas/sitemap/0.9"&lt;/span&gt;);
    xmlTextWriter.WriteEndAttribute();

    &lt;span style="color: #008000"&gt;//Get &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt;'s StartPage (not the RootPage!)&lt;/span&gt;
    PageData p = &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt;.DataFactory.Instance.GetPage(PageReference.StartPage);

    &lt;span style="color: #008000"&gt;//SiteMaps can only contain unique urls so maintain a list of added urls&lt;/span&gt;
    List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; alreadyAddedUrls = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt;();

    &lt;span style="color: #008000"&gt;//Now call recursive method to populate every published/visible etc page&lt;/span&gt;
    RenderNodesToSiteMap(
        context,
        xmlTextWriter,
        alreadyAddedUrls,
        p);

    &lt;span style="color: #008000"&gt;//Close the root element&lt;/span&gt;
    xmlTextWriter.WriteEndElement();
    &lt;span style="color: #008000"&gt;//end of document&lt;/span&gt;
    xmlTextWriter.WriteEndDocument();
    &lt;span style="color: #008000"&gt;//finally close the XMLTextWriter&lt;/span&gt;
    xmlTextWriter.Close();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Finally we need to add a method that will be recursively called for each published page in the site:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Recursively converts the given page into XML for use in the sitemap.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="context"&amp;gt;Current Context&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="xmlTextWriter"&amp;gt;XMLTextWriter to write give page (p) to&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="alreadyAddedUrls"&amp;gt;List of Urls already added to the SiteMap&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="p"&amp;gt;The page to add to the sitemap&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; RenderNodesToSiteMap(
    HttpContext context,
    XmlTextWriter xmlTextWriter,
    List&amp;lt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;&amp;gt; alreadyAddedUrls,
    PageData p)
{
    &lt;span style="color: #008000"&gt;//Make sure the page is published&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (PageDataUtilities.IsPagePublished(child))
    {
        &lt;span style="color: #008000"&gt;//Get the page's 'Friendly' URL&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; url = PageDataUtilities.GetFriendlyUrl(p, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);

        &lt;span style="color: #008000"&gt;// Make sure this URL is not in the XML already&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!alreadyAddedUrls.Contains(url))
        {
            &lt;span style="color: #008000"&gt;//Add it ready to check later&lt;/span&gt;
            alreadyAddedUrls.Add(url);
            &lt;span style="color: #008000"&gt;//Write the Url element&lt;/span&gt;
            xmlTextWriter.WriteStartElement(&lt;span style="color: #006080"&gt;"url"&lt;/span&gt;);
            &lt;span style="color: #008000"&gt;//Add the location (Url) attribute - making sure its encoded!&lt;/span&gt;
            xmlTextWriter.WriteElementString(&lt;span style="color: #006080"&gt;"loc"&lt;/span&gt;, HttpUtility.HtmlEncode(url));
            &lt;span style="color: #008000"&gt;//Add when it was last modified&lt;/span&gt;
            xmlTextWriter.WriteElementString(
                &lt;span style="color: #006080"&gt;"lastmod"&lt;/span&gt;,
                p.Changed.ToString(&lt;span style="color: #006080"&gt;"u"&lt;/span&gt;, CultureInfo.InvariantCulture).Replace(&lt;span style="color: #006080"&gt;" "&lt;/span&gt;, &lt;span style="color: #006080"&gt;"T"&lt;/span&gt;));
            &lt;span style="color: #008000"&gt;//If its the StartPage set the change frequency to daily&lt;/span&gt;
            &lt;span style="color: #008000"&gt;//and the priority to 1&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (p.PageLink == PageReference.StartPage)
            {
                xmlTextWriter.WriteElementString(
                &lt;span style="color: #006080"&gt;"changefreq"&lt;/span&gt;,
                &lt;span style="color: #006080"&gt;"daily"&lt;/span&gt;);
                xmlTextWriter.WriteElementString(
                    &lt;span style="color: #006080"&gt;"priority"&lt;/span&gt;,
                    &lt;span style="color: #006080"&gt;"1.0"&lt;/span&gt;);
            }
            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #008000"&gt;//Otherwise weekly and a lower priority&lt;/span&gt;
            {
                xmlTextWriter.WriteElementString(
                &lt;span style="color: #006080"&gt;"changefreq"&lt;/span&gt;,
                &lt;span style="color: #006080"&gt;"weekly"&lt;/span&gt;);
                xmlTextWriter.WriteElementString(
                 &lt;span style="color: #006080"&gt;"priority"&lt;/span&gt;,
                 &lt;span style="color: #006080"&gt;"0.6"&lt;/span&gt;);
            }
            &lt;span style="color: #008000"&gt;//Close the URL node&lt;/span&gt;
            xmlTextWriter.WriteEndElement();
        }
        &lt;span style="color: #008000"&gt;//Now loop through all the &lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (PageData child &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt;.DataFactory.Instance.GetChildren(p.PageLink))
        {

            RenderNodesToSiteMap(
                context,
                xmlTextWriter,
                alreadyAddedUrls,
                child);

        }
    }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;With all that done the last thing is to register it in the Web.config (inside the &lt;em&gt;System.Web&lt;/em&gt; element) as follows:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;httpHandlers&amp;gt;
  ...
  &amp;lt;add 
    path=&lt;span style="color: #006080"&gt;"sitemap.xml"&lt;/span&gt; 
    verb=&lt;span style="color: #006080"&gt;"*"&lt;/span&gt; 
    type=&lt;span style="color: #006080"&gt;"MyLibrary.SearchEngineSiteMap, MyLibrary"&lt;/span&gt; /&amp;gt;
  ...
&amp;lt;/httpHandlers&amp;gt;&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/312.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/12/EPiServer-Dynamic-SiteMap.xml-generator-for-Google.aspx</guid>
            <pubDate>Thu, 12 Jun 2008 10:09:22 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/312.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/12/EPiServer-Dynamic-SiteMap.xml-generator-for-Google.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/312.aspx</wfw:commentRss>
        </item>
        <item>
            <title>EPiServer: Get a Page's Friendly URL</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/09/EPiServer-Get-a-Pages-Friendly-URL.aspx</link>
            <description>&lt;p&gt;As part of my Search Engine friendly SiteMap.xml generator (using a &lt;em&gt;HttpHandler -&lt;/em&gt; expect a blog post shortly...) I needed to output the friendly URL for each page in the site. However a call to PageData.LinkURL returns the actual link to the page (example shown below), not a "friendly" one that gets displayed in the browser address bar, or in any Hyperlink within the site.&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;/MySite/Default.aspx?id=26&amp;amp;epslanguage=en-GB&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I had a look through the EPiServer documentation and couldn't find anything obvious so resorted to creating my own method to do it (shown below). Simply pass the relevant &lt;em&gt;PageData&lt;/em&gt; object to the function and it will return the page's Friendly URL. e.g. &lt;em&gt;/mysite/en-GB/about-us&lt;/em&gt;&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 400px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Get a friendly URL for the given PageData object&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="pd"&amp;gt;The page to get the Friendly URL from&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;param name="Absolute"&amp;gt;Return an absolute path&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;The friendly Url for the given PageData object&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetFriendlyUrl(PageData pd, &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; Absolute)
{
    UrlBuilder url = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; UrlBuilder(pd.LinkURL);
    &lt;span style="color: #008000"&gt;//Call UrlRewriteProvider's ConvertToExternal method&lt;/span&gt;
    EPiServer.Global.UrlRewriteProvider.ConvertToExternal(
       url,
       pd.PageLink,
       UTF8Encoding.UTF8);
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Absolute)
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; url.ToString();
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; StringUtilities.GetBaseUrl() + url.ToString();           
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If you want to use Absolute paths you'll need to add this method:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Gets the base URL from the current Context.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;static&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GetBaseUrl()
{
    &lt;span style="color: #008000"&gt;//First get the current port&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Port = HttpContext.Current.Request.ServerVariables[&lt;span style="color: #006080"&gt;"SERVER_PORT"&lt;/span&gt;];
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Port == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; || Port == &lt;span style="color: #006080"&gt;"80"&lt;/span&gt; || Port == &lt;span style="color: #006080"&gt;"443"&lt;/span&gt;)
        Port = &lt;span style="color: #006080"&gt;""&lt;/span&gt;;
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #008000"&gt;//Its not a standard port so add it&lt;/span&gt;
        Port = &lt;span style="color: #006080"&gt;":"&lt;/span&gt; + Port;
    &lt;span style="color: #008000"&gt;//Now get the protocol (http or https)&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; Protocol = HttpContext.Current.Request.ServerVariables[&lt;span style="color: #006080"&gt;"SERVER_PORT_SECURE"&lt;/span&gt;];
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Protocol == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt; || Protocol == &lt;span style="color: #006080"&gt;"0"&lt;/span&gt;)
        Protocol = &lt;span style="color: #006080"&gt;"http://"&lt;/span&gt;;
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        Protocol = &lt;span style="color: #006080"&gt;"https://"&lt;/span&gt;;
    &lt;span style="color: #008000"&gt;//Finally combine the protocol, sever name and port&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; url = Protocol + HttpContext.Current.Request.ServerVariables[&lt;span style="color: #006080"&gt;"SERVER_NAME"&lt;/span&gt;] + Port;
    &lt;span style="color: #008000"&gt;//EPiServer's url start with a / so remove the url if (when) it contains one&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (url.EndsWith(&lt;span style="color: #006080"&gt;"/"&lt;/span&gt;))
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; url.Remove(url.LastIndexOf(&lt;span style="color: #006080"&gt;"/"&lt;/span&gt;));
    &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; url;
}&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/310.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/09/EPiServer-Get-a-Pages-Friendly-URL.aspx</guid>
            <pubDate>Mon, 09 Jun 2008 11:33:10 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/310.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/09/EPiServer-Get-a-Pages-Friendly-URL.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/310.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C#: Google Map Server Control - Part 2 - Custom EPiServer Property</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/09/C-Google-Map-Server-Control---Part-2---Custom.aspx</link>
            <description>&lt;p&gt;This post tells you how to take what I discussed in &lt;a title="Click here to read part one" href="http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx" target="_blank"&gt;Part 1&lt;/a&gt; and turn it into a custom EPiServer property, so CMS user's can simply enter a postcode and it will call of to Google's Local Search API, return the Coordinates for the postcode and plot a marker on the map. The user can then drag the marker for a more exact location, set the zoom level and finally the type of map (Normal, Satellite or Hybrid). The data is then rendered on the public site using the code from &lt;a title="Click here to read part one" href="http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx" target="_blank"&gt;Part 1&lt;/a&gt;. The screenshot below show's how it will look in EPiServer (click the thumbnail for the full size version):&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blogs.interakting.co.uk/images/blogs_interakting_co_uk/brad/WindowsLiveWriter/CGoogleMapServerControlPart2CustomEPiSer_ED99/GoogleMapEPiServer_2.jpg"&gt;&lt;img style="border-right: 0px; border-top: 0px; margin: 0px 10px 0px 0px; border-left: 0px; border-bottom: 0px" height="243" alt="GoogleMapEPiServer" src="http://blogs.interakting.co.uk/images/blogs_interakting_co_uk/brad/WindowsLiveWriter/CGoogleMapServerControlPart2CustomEPiSer_ED99/GoogleMapEPiServer_thumb.jpg" width="222" align="left" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Creating a custom EPiServer property is relatively easy - although I think I've not quite got the hang of how to store the actual data. It must be converted to a string for storage in the database. I started to use an &lt;em&gt;XmlSerializer&lt;/em&gt; but got confused (mainly as the JavaScript was doing my head in) as to where i should be doing the serialisation. Sadly the only example i could find on the net was how to create a custom property that was a string - about as much use as a chocolate fire guard! So here's my way of doing it - using a comma separated string (dirty I know!) - please feel free to show me the correct way.&lt;/p&gt;  &lt;p&gt;EPiServer properties are split into two parts, the data and UI aspects. The first is how the data is persisted into the database, the second controls how the data is rendered to the page for both the public and on the edit page in the CMS.   &lt;br /&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;1) &lt;em&gt;CoordinateProperty.cs&lt;/em&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Firstly mark your class with the following attribute: &lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;[Serializable]
[PageDefinitionTypePlugIn(
    DisplayName = &lt;span style="color: #006080"&gt;"Coordinate"&lt;/span&gt;, 
    Description = &lt;span style="color: #006080"&gt;"Coordinate for use with (Google) Map Control"&lt;/span&gt;)]
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; CoordinateProperty : PropertyData&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next some properties to help control the map:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; _string;

&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt;? Latitude
{
    get
    {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(String) &amp;amp;&amp;amp; String.Contains(&lt;span style="color: #006080"&gt;','&lt;/span&gt;))
        {
            &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; temp = 0;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;.TryParse(String.Split(&lt;span style="color: #006080"&gt;','&lt;/span&gt;)[0].Trim(), &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; temp))
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; temp;
            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
     }
 }
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt;? Longitude
{
    get
    {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(String) &amp;amp;&amp;amp; String.Contains(&lt;span style="color: #006080"&gt;','&lt;/span&gt;))
        {
            &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; temp = 0;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;.TryParse(String.Split(&lt;span style="color: #006080"&gt;','&lt;/span&gt;)[1].Trim(), &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; temp))
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; temp;
            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        }
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
    }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Zoom
{
    get
        {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(String) &amp;amp;&amp;amp; String.Contains(&lt;span style="color: #006080"&gt;','&lt;/span&gt;))
        {
            &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; temp = 0;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;int&lt;/span&gt;.TryParse(String.Split(&lt;span style="color: #006080"&gt;','&lt;/span&gt;)[2].Trim(), &lt;span style="color: #0000ff"&gt;out&lt;/span&gt; temp))
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; temp;
            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 5;
         }
         &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; 5;
    }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; MapType
{
    get
    {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(String) &amp;amp;&amp;amp; String.Contains(&lt;span style="color: #006080"&gt;','&lt;/span&gt;))
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; String.Split(&lt;span style="color: #006080"&gt;','&lt;/span&gt;)[3].Trim();
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #006080"&gt;"Map"&lt;/span&gt;;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next the implementation for the abstract members of &lt;em&gt;PropertyData&lt;/em&gt;.&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; PropertyDataType Type
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; PropertyDataType.LongString; }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; Type PropertyValueType
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.GetType(); }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; Value
{
    get
    {
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.IsNull)
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;;
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.String;
    }
    set
    {
        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.ThrowIfReadOnly();
        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetPropertyValue(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;delegate&lt;/span&gt;
        {
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.String = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;.ToString();
        });
    }
}
[XmlIgnore]
&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;virtual&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; String
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._string; }
    set
    {
        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.ThrowIfReadOnly();
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (PropertyData.QualifyAsNullString(&lt;span style="color: #0000ff"&gt;value&lt;/span&gt;))
            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Clear();
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt; &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; ((&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._string != &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;) || (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.IsNull))
        {
            &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;._string = &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;;
            &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Modified();
        }
    }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; PropertyData ParseToObject(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str)
{
    XmlSerializer SerializerObj = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; XmlSerializer(&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.GetType());
    &lt;span style="color: #0000ff"&gt;using&lt;/span&gt; (TextReader stream = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; StringReader(str))
    {
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; (CoordinateProperty)SerializerObj.Deserialize(stream);
    }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ParseToSelf(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; str)
{
    String = str;
}
&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetDefaultValue()
{
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.String = &lt;span style="color: #006080"&gt;",,5,Map"&lt;/span&gt;;
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; IPropertyControl CreatePropertyControl()
{
    &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; CoordinatePropertyControl();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;2) &lt;u&gt;&lt;em&gt;CoordinatePropertyControl.cs&lt;/em&gt;&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;With that done we now need to control how the above class is rendered. First we need to add the four Textboxes:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;TextBox latitiude;
TextBox longitude;
TextBox zoom;
TextBox mapType;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next some basic methods, the first just makes it easier further down the line, the second is required:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Gets the CoordinateProperty instance for this IPropertyControl.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;value&amp;gt;The property that is to be displayed or edited.&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; CoordinateProperty CoordinateProperty
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; PropertyData &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; CoordinateProperty; }
}
&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Does the property support in page edit&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;bool&lt;/span&gt; SupportsOnPageEdit
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;; }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next we need to provide code to display the Google Map in VIEW (public) mode, here we'll simply use the class we created in &lt;a title="Click here to read part one" href="http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx" target="_blank"&gt;Part 1&lt;/a&gt; of this post:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Inherited. Create a controls for rendering the property in view mode.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateDefaultControls()
{
    &lt;span style="color: #008000"&gt;//Check if the Latitude and Longitude have values&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (&lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.Latitude.HasValue &amp;amp;&amp;amp; &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.Longitude.HasValue)
    {
        GoogleMap map = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; GoogleMap();
        map.ID = &lt;span style="color: #006080"&gt;"map"&lt;/span&gt;;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Width.IsEmpty)
            map.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(100, UnitType.Percentage);
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            map.Width = Width;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Height.IsEmpty)
            map.Height = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(400, UnitType.Pixel);
        &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            map.Height = Height;

        map.Latitude = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.Latitude.Value;
        map.Longitude = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.Longitude.Value;
        map.Zoom = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.Zoom;
        map.MapType = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.CoordinateProperty.MapType;
        Controls.Add(map);
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Right that's the basics out of the way, now its time to control how the property is rendered in EDIT mode in the CMS, but first we need to add the JavaScript:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; JAVASCRIPT = &lt;span style="color: #006080"&gt;@"
&amp;lt;script src="&lt;/span&gt;&lt;span style="color: #006080"&gt;"http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key={0}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="&lt;/span&gt;&lt;span style="color: #006080"&gt;"http://www.google.com/uds/api?file=uds.js&amp;amp;amp;v=1.0&amp;amp;amp;key={1}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;
var map;
var localSearch = new GlocalSearch();

function usePointFromPostcode(postcode, callbackFunction) {{
    localSearch.setSearchCompleteCallback(null, 
        function() {{
            if (localSearch.results[0])
            {{        
                var resultLat = localSearch.results[0].lat;
                var resultLng = localSearch.results[0].lng;
                var point = new GLatLng(resultLat,resultLng);
                callbackFunction(point, 17);
            }}else{{
                alert("&lt;/span&gt;&lt;span style="color: #006080"&gt;"Postcode not found!"&lt;/span&gt;&lt;span style="color: #006080"&gt;");
            }}
        }});    
    localSearch.execute(postcode + "&lt;/span&gt;&lt;span style="color: #006080"&gt;", UK"&lt;/span&gt;&lt;span style="color: #006080"&gt;");
}}

function mapLoad() {{
    if (GBrowserIsCompatible()) {{
    //check map not already created!
        if(!map)
        {{
        map = new GMap2(document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{5}"&lt;/span&gt;&lt;span style="color: #006080"&gt;"));
        map.addControl(new GLargeMapControl());
        map.addControl(new GMapTypeControl());

        var mType = document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{7}"&lt;/span&gt;&lt;span style="color: #006080"&gt;").value;
        if(mType == "&lt;/span&gt;&lt;span style="color: #006080"&gt;"Hybrid"&lt;/span&gt;&lt;span style="color: #006080"&gt;")
            map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_HYBRID_MAP);
        else if(mType == "&lt;/span&gt;&lt;span style="color: #006080"&gt;"Satellite"&lt;/span&gt;&lt;span style="color: #006080"&gt;")
            map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_SATELLITE_MAP);
        else
            map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);

        GEvent.addListener(map, "&lt;/span&gt;&lt;span style="color: #006080"&gt;"zoomend"&lt;/span&gt;&lt;span style="color: #006080"&gt;", function(oldLevel, newLevel) {{
            //alert("&lt;/span&gt;&lt;span style="color: #006080"&gt;"Old Zoom: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + oldLevel + "&lt;/span&gt;&lt;span style="color: #006080"&gt;" New Level: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + newLevel);
            document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{6}"&lt;/span&gt;&lt;span style="color: #006080"&gt;").value = newLevel;
        }});

        GEvent.addListener(map, "&lt;/span&gt;&lt;span style="color: #006080"&gt;"maptypechanged"&lt;/span&gt;&lt;span style="color: #006080"&gt;", function() {{
            document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{7}"&lt;/span&gt;&lt;span style="color: #006080"&gt;").value = map.getCurrentMapType().getName();
            document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{6}"&lt;/span&gt;&lt;span style="color: #006080"&gt;").value = map.getZoom();
        }});
        
        }}
    }}
}}

function addLoadEvent(func) {{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {{
    window.onload = func;
  }} else {{
    window.onload = function() {{
      oldonload();
      func();
    }}
  }}
}}

function addUnLoadEvent(func) {{
    var oldonunload = window.onunload;
    if (typeof window.onunload != 'function') {{
      window.onunload = func;
    }} else {{
      window.onunload = function() {{
        oldonunload();
        func();
      }}
    }}
}}

function placeMarkerAtPoint(point, zoom)
{{
    if(!map)
    {{
        mapLoad();
    }}
    var marker = new GMarker(point, {{draggable: true}});
    GEvent.addListener(marker, "&lt;/span&gt;&lt;span style="color: #006080"&gt;"dragstart"&lt;/span&gt;&lt;span style="color: #006080"&gt;", function() {{
        map.closeInfoWindow();
    }});
    GEvent.addListener(marker, "&lt;/span&gt;&lt;span style="color: #006080"&gt;"dragend"&lt;/span&gt;&lt;span style="color: #006080"&gt;", function() {{
        LoadCoordinates(marker.getPoint(), document.getElementById('{2}'), document.getElementById('{3}'));
        marker.openInfoWindowHtml("&lt;/span&gt;&lt;span style="color: #006080"&gt;"Lat: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + marker.getPoint().lat() + "&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;lt;br /&amp;gt;Lng: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + marker.getPoint().lng());
    }});
    map.clearOverlays();
    map.addOverlay(marker);
    setCenterToPoint(point, zoom);
    LoadCoordinates(point, document.getElementById('{2}'), document.getElementById('{3}'));
}}

function setCenterToPoint(point, zoom)
{{
    map.setCenter(point, parseInt(zoom));
}}

function showPointLatLng(point)
{{
    alert("&lt;/span&gt;&lt;span style="color: #006080"&gt;"Latitude: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + point.lat() + "&lt;/span&gt;&lt;span style="color: #006080"&gt;"\nLongitude: "&lt;/span&gt;&lt;span style="color: #006080"&gt;" + point.lng());
}}
function LoadCoordinates(point, txtLat, txtLng)
{{
    txtLat.value = point.lat();
    txtLng.value = point.lng();
}}

addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);
&amp;lt;/script&amp;gt;"&lt;/span&gt;;

&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; EXISTING = &lt;span style="color: #006080"&gt;@"
&amp;lt;script type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;
    placeMarkerAtPoint(new GLatLng({0},{1}),{2});
&amp;lt;/script&amp;gt;"&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Create the controls needed to edit the property&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateEditControls()
{
    &lt;span style="color: #008000"&gt;//Create controls required to edit the property&lt;/span&gt;
    latitiude = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TextBox();
    longitude = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TextBox();
    zoom = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TextBox();
    mapType = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TextBox();
    Label lLat = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Label();
    Label lLong = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Label();
    Label lZoom = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Label();
    Label lMapType = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Label();
    Literal brk1 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Literal();
    Literal brk2 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Literal();
    Literal brk3 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Literal();
    Literal brk4 = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Literal();
    Label lPost = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Label();
    TextBox txtPostCode = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; TextBox();
    Button btn = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Button();
    Panel Div = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Panel();

    &lt;span style="color: #008000"&gt;//Set the line break text.&lt;/span&gt;
    brk1.Text = &lt;span style="color: #006080"&gt;"&amp;lt;br /&amp;gt;"&lt;/span&gt;;
    brk2.Text = &lt;span style="color: #006080"&gt;"&amp;lt;br /&amp;gt;"&lt;/span&gt;;
    brk3.Text = &lt;span style="color: #006080"&gt;"&amp;lt;br /&amp;gt;"&lt;/span&gt;;
    brk4.Text = &lt;span style="color: #006080"&gt;"&amp;lt;br /&amp;gt;"&lt;/span&gt;;

    &lt;span style="color: #008000"&gt;//Set the Latitude TextBox properties&lt;/span&gt;
    latitiude.ID = &lt;span style="color: #006080"&gt;"latitiude"&lt;/span&gt;;
    latitiude.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginLeft, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    latitiude.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(140, UnitType.Pixel);

    &lt;span style="color: #008000"&gt;//Set the Longitude TextBox properties&lt;/span&gt;
    longitude.ID = &lt;span style="color: #006080"&gt;"longitude"&lt;/span&gt;;
    longitude.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginLeft, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    longitude.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(140, UnitType.Pixel);

    &lt;span style="color: #008000"&gt;//Set the Postcode TextBox properties&lt;/span&gt;
    txtPostCode.ID = &lt;span style="color: #006080"&gt;"postcode"&lt;/span&gt;;
    txtPostCode.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(140, UnitType.Pixel);
    txtPostCode.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginLeft, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    txtPostCode.Style.Add(&lt;span style="color: #006080"&gt;"text-transform"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"uppercase"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Set the MapType TextBox properties&lt;/span&gt;
    mapType.ID = &lt;span style="color: #006080"&gt;"maptype"&lt;/span&gt;;
    mapType.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginLeft, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    mapType.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(65, UnitType.Pixel);

    &lt;span style="color: #008000"&gt;//Set the Zoom TextBox properties&lt;/span&gt;
    zoom.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginLeft, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    zoom.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(65, UnitType.Pixel);

    &lt;span style="color: #008000"&gt;//Set the latitude label properties&lt;/span&gt;
    lLat.Text = &lt;span style="color: #006080"&gt;"Latitude"&lt;/span&gt;;
    lLat.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(60, UnitType.Pixel);
    lLat.Style.Add(&lt;span style="color: #006080"&gt;"float"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"left"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Set the longitude label properties&lt;/span&gt;
    lLong.Text = &lt;span style="color: #006080"&gt;"Longitude"&lt;/span&gt;;
    lLong.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(60, UnitType.Pixel);
    lLong.Style.Add(&lt;span style="color: #006080"&gt;"float"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"left"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Set the map type label properties&lt;/span&gt;
    lMapType.Text = &lt;span style="color: #006080"&gt;"Map Type"&lt;/span&gt;;
    lMapType.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(60, UnitType.Pixel);
    lMapType.Style.Add(&lt;span style="color: #006080"&gt;"float"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"left"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Set the postcode label properties&lt;/span&gt;
    lPost.Text = &lt;span style="color: #006080"&gt;"Post Code"&lt;/span&gt;;
    lPost.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(60, UnitType.Pixel);
    lPost.Style.Add(&lt;span style="color: #006080"&gt;"float"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"left"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Set the zoom label properties&lt;/span&gt;
    lZoom.Text = &lt;span style="color: #006080"&gt;"Zoom"&lt;/span&gt;;
    lZoom.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(60, UnitType.Pixel);
    lZoom.Style.Add(&lt;span style="color: #006080"&gt;"float"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"left"&lt;/span&gt;);
                    
    &lt;span style="color: #008000"&gt;//Set the button properties&lt;/span&gt;
    btn.Text = &lt;span style="color: #006080"&gt;"Look Up"&lt;/span&gt;;
    
    &lt;span style="color: #008000"&gt;//Set the map canvas&lt;/span&gt;
    Div.ID = &lt;span style="color: #006080"&gt;"mapDiv"&lt;/span&gt;;
    Div.Style.Add(System.Web.UI.HtmlTextWriterStyle.MarginTop, &lt;span style="color: #006080"&gt;"20px"&lt;/span&gt;);
    Div.Width = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(400, UnitType.Pixel);
    Div.Height = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Unit(400, UnitType.Pixel);

    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ApplyControlAttributes(latitiude);
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ApplyControlAttributes(longitude);
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ApplyControlAttributes(zoom);

    &lt;span style="color: #008000"&gt;//Add the controls to the controls collection&lt;/span&gt;
    Controls.Add(lPost);
    Controls.Add(txtPostCode);
    Controls.Add(btn);
    Controls.Add(brk1);
    Controls.Add(lLat);
    Controls.Add(latitiude);
    Controls.Add(brk2);
    Controls.Add(lLong);
    Controls.Add(longitude);
    Controls.Add(brk3);
    Controls.Add(lZoom);
    Controls.Add(zoom);
    Controls.Add(brk4);
    Controls.Add(lMapType);
    Controls.Add(mapType);
    Controls.Add(Div);

    &lt;span style="color: #008000"&gt;//Add the JavaScript required to render the google map&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsClientScriptIncludeRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(CoordinatePropertyControl), &lt;span style="color: #006080"&gt;"MAP"&lt;/span&gt;))
        Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(CoordinatePropertyControl), &lt;span style="color: #006080"&gt;"MAP"&lt;/span&gt;, 
            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(JAVASCRIPT,
            WebConfigurationManager.AppSettings[&lt;span style="color: #006080"&gt;"GoogleMapKey"&lt;/span&gt;], &lt;span style="color: #008000"&gt;//0&lt;/span&gt;
            WebConfigurationManager.AppSettings[&lt;span style="color: #006080"&gt;"GoogleMapKey"&lt;/span&gt;], &lt;span style="color: #008000"&gt;//1&lt;/span&gt;
            latitiude.ClientID, &lt;span style="color: #008000"&gt;//2&lt;/span&gt;
            longitude.ClientID, &lt;span style="color: #008000"&gt;//3&lt;/span&gt;
            &lt;span style="color: #006080"&gt;""&lt;/span&gt;, &lt;span style="color: #008000"&gt;//4&lt;/span&gt;
            Div.ClientID, &lt;span style="color: #008000"&gt;//5&lt;/span&gt;
            zoom.ClientID, &lt;span style="color: #008000"&gt;//6&lt;/span&gt;
            mapType.ClientID, &lt;span style="color: #008000"&gt;//7&lt;/span&gt;
            PropertyData.Name &lt;span style="color: #008000"&gt;//8&lt;/span&gt;
            ));

    &lt;span style="color: #008000"&gt;//Add the onclick javascript to the postcode&lt;/span&gt;
    &lt;span style="color: #008000"&gt;//lookup button&lt;/span&gt;
    btn.Attributes.Add(&lt;span style="color: #006080"&gt;"onclick"&lt;/span&gt;, 
        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;"usePointFromPostcode(document.getElementById('{0}').value, placeMarkerAtPoint); return false;"&lt;/span&gt;,
        txtPostCode.ClientID));

    &lt;span style="color: #008000"&gt;//Make the map type and zoom textboxes&lt;/span&gt;
    &lt;span style="color: #008000"&gt;//readonly as they are set by the google&lt;/span&gt;
    &lt;span style="color: #008000"&gt;//map control.&lt;/span&gt;
    zoom.Attributes.Add(&lt;span style="color: #006080"&gt;"readonly"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"true"&lt;/span&gt;);
    mapType.Attributes.Add(&lt;span style="color: #006080"&gt;"readonly"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"true"&lt;/span&gt;);

    &lt;span style="color: #008000"&gt;//Lastly populate the edit controls with values from the underlying CoordinateProperty&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.SetupEditControls();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;With that done we need to override the method which will populate the edit controls with values from the underlying CoordinateProperty (either default of from the database)&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Inherited. Initialize the value of the TextBox control.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; SetupEditControls()
{
    &lt;span style="color: #008000"&gt;//Set the zoom and map type textbox values&lt;/span&gt;
    zoom.Text = CoordinateProperty.Zoom.ToString();
    mapType.Text = CoordinateProperty.MapType;

    &lt;span style="color: #008000"&gt;//If the Latitude/Longitude have values set the relevant&lt;/span&gt;
    &lt;span style="color: #008000"&gt;//textbox properties and add the GoogleMap Javascript&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (CoordinateProperty.Latitude.HasValue &amp;amp;&amp;amp; CoordinateProperty.Longitude.HasValue)
    {
        latitiude.Text = CoordinateProperty.Latitude.Value.ToString();
        longitude.Text = CoordinateProperty.Longitude.Value.ToString();

        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsStartupScriptRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(CoordinatePropertyControl), 
            &lt;span style="color: #006080"&gt;"EXISTING"&lt;/span&gt;))
        {
            Page.ClientScript.RegisterStartupScript(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(CoordinatePropertyControl), 
                &lt;span style="color: #006080"&gt;"EXISTING"&lt;/span&gt;,
                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(EXISTING,
                    latitiude.Text,
                    longitude.Text,
                    zoom.Text));
        }
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Finally we must override the method which sets the value of the underlying CoordinateProperty with values entered in the UI by the user:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// Inherited. Applies changes for the posted data to the page's properties when the RenderType property&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// is set to Edit.&lt;/span&gt;
&lt;span style="color: #008000"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; ApplyEditChanges()
{
    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.SetValue(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(CultureInfo.InvariantCulture, &lt;span style="color: #006080"&gt;"{0},{1},{2},{3}"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.latitiude.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.longitude.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.zoom.Text, &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.mapType.Text));
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And that's it - put it all together and you'll be able to configure a Google Map 'widget' in EPiServer.&lt;/p&gt;

&lt;p&gt;Oh - one small thing to note - the above JavaScript will only allow for ONE &lt;em&gt;CoordinateProperty&lt;/em&gt; to be added to a &lt;em&gt;PageType&lt;/em&gt;. If you add more than one to the same &lt;em&gt;PageType&lt;/em&gt; it will break. If I get time I'll change it, but our current requirement is only for one map per page - sorry!&lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/309.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/09/C-Google-Map-Server-Control---Part-2---Custom.aspx</guid>
            <pubDate>Mon, 09 Jun 2008 09:24:21 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/309.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/09/C-Google-Map-Server-Control---Part-2---Custom.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/309.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C#: Google Map Server Control - Part 1</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx</link>
            <description>&lt;p&gt;Following on from my Google Analytics server control, I wanted make something "cooler", so creating a Server Control to render a Google Map control seemed ideal. Part 1 covers the creation of the this control, stay tuned for &lt;a title="Read part two here" href="http://blogs.interakting.co.uk/brad/archive/2008/06/09/C-Google-Map-Server-Control---Part-2---Custom.aspx" target="_blank"&gt;part 2&lt;/a&gt; which will focus on creating a custom EPiServer property so it can be used in the EPiServer edit area, featuring Geocoding to lookup the coordinates from a UK post code, Map type selection and zoom level. &lt;/p&gt;  &lt;p&gt;Anyway here's the generic bit that can be used on any site...&lt;/p&gt;  &lt;p&gt;First off we need a set of basic properties to hold Latitude, Longitude, Zoom Level and Map Type:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 238px; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; Latitude
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetPropertyValue(&lt;span style="color: #006080"&gt;"Latitude"&lt;/span&gt;, (&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;)0); }
    set { SetPropertyValue(&lt;span style="color: #006080"&gt;"Latitude"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;double&lt;/span&gt; Longitude
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetPropertyValue(&lt;span style="color: #006080"&gt;"Longitude"&lt;/span&gt;, (&lt;span style="color: #0000ff"&gt;double&lt;/span&gt;)0); }
    set { SetPropertyValue(&lt;span style="color: #006080"&gt;"Longitude"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;int&lt;/span&gt; Zoom
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetPropertyValue(&lt;span style="color: #006080"&gt;"Zoom"&lt;/span&gt;, 5); }
    set { SetPropertyValue(&lt;span style="color: #006080"&gt;"Zoom"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
}
&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; MapType
{
    get { &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; GetPropertyValue(&lt;span style="color: #006080"&gt;"MapType"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"Map"&lt;/span&gt;); }
    set { SetPropertyValue(&lt;span style="color: #006080"&gt;"MapType"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;value&lt;/span&gt;); }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next come's the rather complex looking JavaScript code. I've done it so that it will allow multiple controls to be placed on the same page. IMPORTANT: Make sure you {0} in &lt;em&gt;COMMONJAVASCRIPT &lt;/em&gt;is your unique Google Maps/API Key, which is generated on a per domain basis.&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; COMMONJAVASCRIPT = &lt;span style="color: #006080"&gt;@"
        &amp;lt;script src="&lt;/span&gt;&lt;span style="color: #006080"&gt;"http://maps.google.com/maps?file=api&amp;amp;amp;v=2&amp;amp;amp;key={0}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;&amp;lt;/script&amp;gt;
        &amp;lt;script src="&lt;/span&gt;&lt;span style="color: #006080"&gt;"http://www.google.com/uds/api?file=uds.js&amp;amp;amp;v=1.0&amp;amp;amp;key={0}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;&amp;lt;/script&amp;gt;"&lt;/span&gt;;
        
        &lt;span style="color: #0000ff"&gt;private&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; JAVASCRIPT = &lt;span style="color: #006080"&gt;@"
        &amp;lt;script type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;
        function GoogleMapLoad{6}() {{
          if (GBrowserIsCompatible()) {{
            var map = new GMap2(document.getElementById("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{3}"&lt;/span&gt;&lt;span style="color: #006080"&gt;"));
        
                if("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{5}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" == "&lt;/span&gt;&lt;span style="color: #006080"&gt;"Hybrid"&lt;/span&gt;&lt;span style="color: #006080"&gt;")
                   map.setCenter(new GLatLng({1},{2}), parseInt({4}), G_HYBRID_MAP);
                else if("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{5}"&lt;/span&gt;&lt;span style="color: #006080"&gt;" == "&lt;/span&gt;&lt;span style="color: #006080"&gt;"Satellite"&lt;/span&gt;&lt;span style="color: #006080"&gt;")
                   map.setCenter(new GLatLng({1},{2}), parseInt({4}), G_SATELLITE_MAP);
                else
                   map.setCenter(new GLatLng({1},{2}), parseInt({4}), G_NORMAL_MAP);
                
                var point = new GLatLng({1},{2});
                map.addOverlay(new GMarker(point));
                map.addControl(new GMapTypeControl());
                map.addControl(new GLargeMapControl());
            }}
        }}
        &amp;lt;/script&amp;gt;"&lt;/span&gt;;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next we need to override the default tag that the server control would typically render (span) with a div, so that the Google map has a "canvas".&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;//Google map must be rendered inside a &amp;lt;DIV&amp;gt; tag, so we'll override the default &amp;lt;SPAN&amp;gt;.&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; HtmlTextWriterTag TagKey
{
    get
    {
        &lt;span style="color: #008000"&gt;//Return DIV not SPAN&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;return&lt;/span&gt; HtmlTextWriterTag.Div;
    }
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And last but not least, the overloaded &lt;em&gt;CreateChildControls()&lt;/em&gt;. Firstly we check to see if there are (valid) Latitude and longitude values, if there is we register two blocks of JavaScript. Notice the second block's key includes the controls ID - which allows multiple maps to be used on the same page. The first 'common' block will only be registered once regardless of how many maps on the page. The second block has five strings passed to it which include the Google API Key (stored in the AppSettings) the control's ClientID (so the map's canvas can be accessed) along with the lat/lng/zoom etc.&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateChildControls()
{
    &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (Latitude != 0 &amp;amp;&amp;amp; Longitude != 0)
    {
        &lt;span style="color: #008000"&gt;//Check if the COMMON google map javascript block has been registered&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsClientScriptBlockRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMap"&lt;/span&gt;))
            Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMap"&lt;/span&gt;, COMMONJAVASCRIPT);

        &lt;span style="color: #008000"&gt;//Check if the google map javascript block for THIS map has been registered&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsClientScriptBlockRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMap"&lt;/span&gt; + ID))
            Page.ClientScript.RegisterClientScriptBlock(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMap"&lt;/span&gt; + ID, 
                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(CultureInfo.InvariantCulture, JAVASCRIPT,
                        WebConfigurationManager.AppSettings[&lt;span style="color: #006080"&gt;"GoogleMapKey"&lt;/span&gt;], &lt;span style="color: #008000"&gt;//0&lt;/span&gt;
                        Latitude,  &lt;span style="color: #008000"&gt;//1&lt;/span&gt;
                        Longitude, &lt;span style="color: #008000"&gt;//2&lt;/span&gt;
                        &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.ClientID, &lt;span style="color: #008000"&gt;//3&lt;/span&gt;
                        Zoom, &lt;span style="color: #008000"&gt;// 4&lt;/span&gt;
                        MapType, &lt;span style="color: #008000"&gt;//5&lt;/span&gt;
                        ClientID &lt;span style="color: #008000"&gt;//6), &lt;/span&gt;
                    &lt;span style="color: #0000ff"&gt;false&lt;/span&gt;);

        &lt;span style="color: #008000"&gt;//Now we need to add the google maps onload JavaScript function for THIS MAP ONLY (it its not be added already)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsStartupScriptRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMapLoad"&lt;/span&gt; + ID))
            Page.ClientScript.RegisterStartupScript(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMapLoad"&lt;/span&gt; + ID, &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;"GoogleMapLoad{0}();"&lt;/span&gt;, ClientID), &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);

        &lt;span style="color: #008000"&gt;//Now we need to add the google maps onUNload JavaScript function (it its not be added already)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsStartupScriptRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMapUnload"&lt;/span&gt;))
            Page.ClientScript.RegisterStartupScript(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleMap), &lt;span style="color: #006080"&gt;"GoogleMapUnload"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"window.onunload = function () { GUnload(); };"&lt;/span&gt;, &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;);
    }
    &lt;span style="color: #008000"&gt;//now call the base controls Create Child Controls&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.CreateChildControls();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;UPDATED:&lt;/strong&gt; Check out &lt;a href="http://blogs.interakting.co.uk/brad/archive/2008/06/09/C-Google-Map-Server-Control---Part-2---Custom.aspx" target="_blank"&gt;part 2&lt;/a&gt; for how to use this with EPiServer.&lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/308.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx</guid>
            <pubDate>Fri, 06 Jun 2008 15:17:03 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/308.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/06/C-Google-Map-Server-Control---Part-1.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/308.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C#: Google Analytics Server Control</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/04/C-Google-Analytics-Server-Control.aspx</link>
            <description>&lt;p&gt;Today I've been consolidating UserControls that I've found myself using in one &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt; project after another into a nice Server Control library. One such control that gets used on every site (even non-EPiServer ones) is one which adds the &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; &lt;a title="Google Analytics" href="http://www.google.com/analytics" target="_blank"&gt;Analytics&lt;/a&gt; JavaScript code to the page. I decided this would be the first UserControl to migrate.&lt;/p&gt;  &lt;p&gt;Firstly I created a constant &lt;em&gt;GoogleAnalyticsJavaScript&lt;/em&gt; which holds the JavaScript string to be added to the page. The only change I needed to make was to dynamically add the unique &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; &lt;a title="Google Analytics" href="http://www.google.com/analytics" target="_blank"&gt;Analytics&lt;/a&gt; tracking code that was generated specifically for my domain. I could have stored this as a dynamic property in &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt;, but decided that since it would hardly change, if ever, that the AppSettings would be a more suitable place. (This also makes the code more portable - sorry &lt;a title="EPiServer Content Management System" href="http://www.episerver.com" target="_blank"&gt;EPiServer&lt;/a&gt;!) &lt;/p&gt;  &lt;p&gt;So I simply overrided the &lt;em&gt;CreateChildControls&lt;/em&gt; and perform a quick check to make sure that there is a AppSetting with a Key of &lt;em&gt;GoogleAnalyticsKey&lt;/em&gt; and that the script hasn't already been added to the page. Next i had to register it as a startup script (I chose startup script so it would be rendered near the end of body tag - perfect for situations where I want to add specific custom &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; tracking to links within my page - I.e. downloads, RSS feeds etc. Registering a standard script block would appear at the top of the body meaning that custom link tracking wouldn't work).&lt;/p&gt;  &lt;p&gt;The code listing is shown below:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 400px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 426px; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 582px; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; GoogleAnalytics : InteraktingServerControl
{
    &lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;const&lt;/span&gt; &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; GoogleAnalyticsJavaScript = &lt;span style="color: #006080"&gt;@"
        &amp;lt;script type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;
        /* &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; TRACKING CODE */
        var gaJsHost = (("&lt;/span&gt;&lt;span style="color: #006080"&gt;"https:"&lt;/span&gt;&lt;span style="color: #006080"&gt;" == document.location.protocol) ? "&lt;/span&gt;&lt;span style="color: #006080"&gt;"https://ssl."&lt;/span&gt;&lt;span style="color: #006080"&gt;" : "&lt;/span&gt;&lt;span style="color: #006080"&gt;"http://www."&lt;/span&gt;&lt;span style="color: #006080"&gt;");
        document.write(unescape("&lt;/span&gt;&lt;span style="color: #006080"&gt;"%3Cscript src='"&lt;/span&gt;&lt;span style="color: #006080"&gt;" + gaJsHost + "&lt;/span&gt;&lt;span style="color: #006080"&gt;"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"&lt;/span&gt;&lt;span style="color: #006080"&gt;"));
        &amp;lt;/script&amp;gt;
        &amp;lt;script type="&lt;/span&gt;&lt;span style="color: #006080"&gt;"text/javascript"&lt;/span&gt;&lt;span style="color: #006080"&gt;"&amp;gt;
        var pageTracker = _gat._getTracker("&lt;/span&gt;&lt;span style="color: #006080"&gt;"{0}"&lt;/span&gt;&lt;span style="color: #006080"&gt;");
        pageTracker._initData();
        pageTracker._trackPageview();
        /* &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; TRACKING CODE */
        &amp;lt;/script&amp;gt;"&lt;/span&gt;;

    &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; CreateChildControls()
    {
        &lt;span style="color: #008000"&gt;//Make sure the &lt;a title="Google" href="http://www.google.co.uk" target="_blank"&gt;Google&lt;/a&gt; &lt;a title="Google Analytics" href="http://www.google.com/analytics" target="_blank"&gt;Analytics&lt;/a&gt; key is set in the AppSettings&lt;/span&gt;
        &lt;span style="color: #008000"&gt;//Also make sure the script hasn't been registered already&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!&lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.IsNullOrEmpty(WebConfigurationManager.AppSettings[&lt;span style="color: #006080"&gt;"GoogleAnalyticsKey"&lt;/span&gt;])
             &amp;amp;&amp;amp; Page.ClientScript.IsStartupScriptRegistered(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleAnalytics), &lt;span style="color: #006080"&gt;"GoogleAnalyticsKey"&lt;/span&gt; + ID))
        {
            Page.ClientScript.RegisterStartupScript(
                &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(GoogleAnalytics),
                &lt;span style="color: #006080"&gt;"GoogleAnalyticsKey"&lt;/span&gt; + ID,
                &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(
                    GoogleAnalyticsJavaScript, 
                    WebConfigurationManager.AppSettings[&lt;span style="color: #006080"&gt;"GoogleAnalyticsKey"&lt;/span&gt;]
                    )
                );
         }
        &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.CreateChildControls();
    }
}&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/305.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/04/C-Google-Analytics-Server-Control.aspx</guid>
            <pubDate>Wed, 04 Jun 2008 11:20:35 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/305.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/04/C-Google-Analytics-Server-Control.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/305.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C# Register onUnload JavaScript programmatically in code-behind</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/06/03/C-Register-onUnload-JavaScript-programmatically-in-code-behind.aspx</link>
            <description>&lt;p&gt;Having just created a Google Map server control I spent some time trying to register the relevant unload scripts that the Google API demands. However there was no easy way to get access to the body tag, and I certainly didn't want to have to edit the body tag, adding &lt;em&gt;runat="server"&lt;/em&gt; as that would ruin my nicely "wrapped" control, I simply want a developer to drag it out of their Visual Studio Toolbox and it work...&lt;/p&gt;  &lt;p&gt;So after some thought I tried the following, which worked a treat:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 186px; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #008000"&gt;//Now we need to add the google maps &lt;/span&gt;
&lt;span style="color: #008000"&gt;//ONUNLOAD JavaScript function (it its not be added already)&lt;/span&gt;
&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!Page.ClientScript.IsStartupScriptRegistered(
                 &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(MyControl), &lt;span style="color: #006080"&gt;"GoogleMapUnload"&lt;/span&gt;))
{
    Page.ClientScript.RegisterStartupScript(
        &lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(MyControl), 
        &lt;span style="color: #006080"&gt;"GoogleMapUnload"&lt;/span&gt;, 
        &lt;span style="color: #006080"&gt;"window.onunload = function () { GUnload(); };"&lt;/span&gt;, 
        &lt;span style="color: #0000ff"&gt;true&lt;/span&gt;); 
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So simply replace the &lt;em&gt;GUnload();&lt;/em&gt; with your own custom JavaScript - you get the idea....&lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/304.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/06/03/C-Register-onUnload-JavaScript-programmatically-in-code-behind.aspx</guid>
            <pubDate>Tue, 03 Jun 2008 14:22:59 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/304.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/06/03/C-Register-onUnload-JavaScript-programmatically-in-code-behind.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/304.aspx</wfw:commentRss>
        </item>
        <item>
            <title>EPiServer Language Selector</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/05/28/EPiServer-Language-Selector.aspx</link>
            <description>&lt;p&gt;Today I needed to create a UserControl to allow a user to select to view the current page from a list of enabled languages. To begin with I thought it would be a fairly easy task, by simply calling &lt;em&gt;GetLanguageBranches()&lt;/em&gt; in the &lt;em&gt;DataFactory&lt;/em&gt; class. However this ONLY returns the versions of the page that have been translated, which didn't suit me as our requirement was that ALL (enabled) languages should be displayed in the language selector, and if a language version doesn't exist for the specific page then the fallback language be used. &lt;/p&gt;  &lt;p&gt;So next I tried looping through the results from &lt;em&gt;EPiServer.DataAbstraction.LanguageBranch.ListEnabled();&lt;/em&gt; This seemed to be just what I needed, so I set about looping through all the languages, displaying a hyperlink for each, with the &lt;em&gt;Text&lt;/em&gt; being the name of the language. The &lt;em&gt;NavigateUrl&lt;/em&gt; property was much trickier - why is nothing ever simple! &lt;/p&gt;  &lt;p&gt;So next I set about trying to return a language specific version of a page for each of my enabled languages, at first I tried using:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 38px; background-color: #f4f4f4; border-bottom-style: none"&gt;EPiServer.DataFactory.Instance.GetPage(
&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LanguageSelector( [Language code here] )).LinkURL &lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;This caused two problems, firstly this only works if the page exists in that language, with a &lt;em&gt;LanguageNotFound&lt;/em&gt; exception thrown otherwise. So in the &lt;em&gt;Catch&lt;/em&gt; block I tried:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 38px; background-color: #f4f4f4; border-bottom-style: none"&gt;EPiServer.DataFactory.Instance.GetPage(
LanguageSelector.FallBack( [Language code here] )).LinkURL &lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Much to my annoyance however, it always rendered to the currently selected language. My first thought was EPiServer's &lt;em&gt;TemplatePage&lt;/em&gt; or a &lt;em&gt;ControlAdapter &lt;/em&gt;were causing this when they generate the "FriendlyUrl", however while debugging I realised that the &lt;em&gt;LinkUrl&lt;/em&gt;  property of the &lt;em&gt;PageData&lt;/em&gt; class had the incorrect language code as part of the query string. So it must use the current culture when generating the URL string, regardless of the actual page.&lt;/p&gt;

&lt;p&gt;Enter &lt;a title="Click to see Steve's Blog" href="http://blogs.interakting.co.uk/steve" target="_blank"&gt;Steve&lt;/a&gt;, who suggested I try setting the culture to that of the SPECIFIC language before getting a reference to the page and getting it's &lt;em&gt;LinkUrl &lt;/em&gt;property, and bingo it worked! The only thing to remember is to make sure I set the culture back to the correct one at the end of the loop to make sure I didn't break anything further down the response.&lt;/p&gt;

&lt;p&gt;Here's the code. I've not included the code listing for the &lt;em&gt;LanguageItem&lt;/em&gt; class to keep the post short, but you should get the gist of what's going on...&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (!IsPostBack)
{
    &lt;span style="color: #008000"&gt;//Create a list to hold LanguageItem's (which simply has 'Name'/'Url'/'ImageUrl' properties)&lt;/span&gt;
    List&amp;lt;LanguageItem&amp;gt; langs = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; List&amp;lt;LanguageItem&amp;gt;();
    &lt;span style="color: #008000"&gt;//Get the current culture as we'll need it later&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; currentCulture = EPiServer.Globalization.GlobalizationSettings.CultureLanguageCode;
    &lt;span style="color: #008000"&gt;//Loop through every enabled language&lt;/span&gt;
    &lt;span style="color: #0000ff"&gt;foreach&lt;/span&gt; (LanguageBranch lang &lt;span style="color: #0000ff"&gt;in&lt;/span&gt; EPiServer.DataAbstraction.LanguageBranch.ListEnabled())
    {
        &lt;span style="color: #008000"&gt;//Set the culture to the language of the link being constructed.&lt;/span&gt;
        EPiServer.Globalization.ContentLanguage.Instance.SetCulture(lang.LanguageID); 
        langs.Add(&lt;span style="color: #0000ff"&gt;new&lt;/span&gt; LanguageItem(
        &lt;span style="color: #008000"&gt;//The name of the language&lt;/span&gt;
        lang.Name,
        &lt;span style="color: #008000"&gt;//Get the current page (but as we've set a new culture it will get the &lt;/span&gt;
        &lt;span style="color: #008000"&gt;//relevant lanaguage if it exists, or the fallback if doesn't.&lt;/span&gt;
        EPiServer.DataFactory.Instance.GetPage(CurrentPage.PageLink).LinkURL,
        &lt;span style="color: #008000"&gt;//Finally generate the url to the Language's Image (e.g. a flag)&lt;/span&gt;
        &lt;span style="color: #0000ff"&gt;string&lt;/span&gt;.Format(&lt;span style="color: #006080"&gt;"~/App_Themes/{0}/Images/Languages/{1}.gif"&lt;/span&gt;, Page.Theme,  lang.LanguageID)));
    }
    &lt;span style="color: #008000"&gt;//Finally set the culture back to the what it was at the beginning.&lt;/span&gt;
    EPiServer.Globalization.ContentLanguage.Instance.SetCulture(currentCulture); 
    &lt;span style="color: #008000"&gt;//Set the LanguageItem list as the DataSource for the repeater and bind&lt;/span&gt;
    rLanguages.DataSource = langs;
    rLanguages.DataBind();
}&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;If anyone happens to know of a 'better' way of doing this please let me know... i spent ages trying to get it to work, and sadly EPiServer's documentation was non-existent. I also couldn't find any blogs/articles on how to do it, which is why i decided to share it with you all...&lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/302.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/05/28/EPiServer-Language-Selector.aspx</guid>
            <pubDate>Wed, 28 May 2008 12:55:54 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/302.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/05/28/EPiServer-Language-Selector.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/302.aspx</wfw:commentRss>
        </item>
        <item>
            <title>C#: Getting round the &amp;quot;Indexed Pixel Format Issue&amp;quot; in GDI+</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/05/21/C-Getting-round-the-quotIndexed-Pixel-Format-Issuequot-in-GDI.aspx</link>
            <description>&lt;p&gt;If you've ever tried to manipulate images in &lt;a title="Microsoft C#" href="http://msdn.microsoft.com/vcsharp/" target="_blank"&gt;C#&lt;/a&gt; using GDI+ you'll almost certainly have come across the following error at some point:&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 16px; background-color: #f4f4f4; border-bottom-style: none"&gt;a graphics &lt;span style="color: #0000ff"&gt;object&lt;/span&gt; cannot be created from an image that has an indexed pixel format&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;I know I have, and it took a fair bit of effort to find the solution so I thought I'd share it.&lt;/p&gt;

&lt;p&gt;Here's a quick background on Pixel Formats... In '&lt;em&gt;Non Indexed&lt;/em&gt;' images, each pixel represents ONE colour. So a pixel might have a value &amp;amp;h0000FF (Red). In '&lt;em&gt;Indexed&lt;/em&gt;' images each pixel value is an index to a so-called 'palette' or 'colour table'. So a pixel might have a value of 3, which means use the colour in palette entry #3 for that pixel.&lt;/p&gt;

&lt;p&gt;For some reason GDI+ doesn't support editing Indexed images (that use the palette/colour table approach). &lt;/p&gt;

&lt;p&gt;Here's a simple work around which, if the Pixel Format is Indexed, will create a new (&lt;em&gt;non-indexed&lt;/em&gt;) Bitmap image from the original image instance &lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.96%; cursor: text; max-height: 300px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 300px; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;Image original = Image.FromFile(SourceImagePath);

&lt;span style="color: #0000ff"&gt;switch&lt;/span&gt; (original.PixelFormat)
{
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Undefined:
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Format1bppIndexed:
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Format4bppIndexed:
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Format8bppIndexed:
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Format16bppGrayScale:
   &lt;span style="color: #0000ff"&gt;case&lt;/span&gt; System.Drawing.Imaging.PixelFormat.Format16bppArgb1555:

       &lt;span style="color: #008000"&gt;// Create a new BitMap object using original Image instance&lt;/span&gt;
       original = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Bitmap(original);
       &lt;span style="color: #0000ff"&gt;break&lt;/span&gt;;
}&lt;/pre&gt;
&lt;/div&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/290.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/05/21/C-Getting-round-the-quotIndexed-Pixel-Format-Issuequot-in-GDI.aspx</guid>
            <pubDate>Wed, 21 May 2008 09:49:04 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/290.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/05/21/C-Getting-round-the-quotIndexed-Pixel-Format-Issuequot-in-GDI.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/290.aspx</wfw:commentRss>
        </item>
        <item>
            <title>URL Rewriting: ASP.NET HyperLink ImageUrl Bug</title>
            <link>http://blogs.interakting.co.uk/brad/archive/2008/05/20/URL-Rewriting-ASP.NET-HyperLink-ImageUrl-Bug.aspx</link>
            <description>&lt;p&gt;I've been experimenting with writing my own &lt;a title="Microsoft C#" href="http://msdn.microsoft.com/vcsharp/" target="_blank"&gt;C#&lt;/a&gt; URL Rewriter using a HttpModule. It's surprisingly simple as &lt;a title="Microsoft .NET " href="http://msdn.microsoft.com/netframework/" target="_blank"&gt;.NET&lt;/a&gt; kindly has the following (where newURL is the path to the actual file) :&lt;/p&gt;  &lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;   &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 28px; background-color: #f4f4f4; border-bottom-style: none"&gt;HttpContext.RewritePath(&lt;span style="color: #0000ff"&gt;string&lt;/span&gt; newURL)&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;So this allows a URL such as:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;/my-friendly-url &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;to actually point to:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;/pages/content.aspx?id=5&lt;/p&gt;

  &lt;p&gt; &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Problem:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;All was going well, but some pages were giving the following error for no apparent reason:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;Cannot use a leading '..' to exit above the top directory.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;After some investigation I tracked the problem down to any asp.net HyperLink controls that had an ImageUrl property set. More specifically those starting with a '~/', if I removed the tilde the problem went away. Suffice to say I wasn't entirely happy about this 'workaround' so set about looking for an answer to why it was happening, and a better solution. &lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cause:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;After what seemed like hours of googling I came across a great article (link at the end of this post) on 4guysfromRolla.com. The problem turns out to be a bug in the HyperLink control, whereby it 'double-resolves' the ImageUrl property (basically it doesn't check if the path has already been resolved further down the stack and calls &lt;em&gt;base.ResolveClientUrl(imageUrl)&lt;/em&gt; every time).&lt;/p&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Solution:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Thankfully the solution is impressively simple through the use of a &lt;a title="Microsoft .NET " href="http://msdn.microsoft.com/netframework/" target="_blank"&gt;.NET&lt;/a&gt; ControlAdapter. If you've not come across them before, ControlAdapters let you hook into (and/or alter) the rendering process of any control, without having to the change the implementation of it in every page (I don't want to have to change all my &amp;lt;asp:HyperLink /&amp;gt; definitions throughout my solution).&lt;/p&gt;

&lt;p&gt;So to fix the problem i'm going to create a ControlAdapter (for all browsers - typically you'd use them for Browser specific rendering differences) that will override the HyperLink's render method, crucially not calling &lt;em&gt;base.ResolveClientUrl(imageUrl), &lt;/em&gt;instead leaving the &lt;em&gt;ImageUrl&lt;/em&gt; value 'as-is'. (see below)&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 400px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; height: 471px; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; HyperLinkControlAdapter : ControlAdapter
    {
        &lt;span style="color: #0000ff"&gt;protected&lt;/span&gt; &lt;span style="color: #0000ff"&gt;override&lt;/span&gt; &lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Render(HtmlTextWriter writer)
        {
            HyperLink hyperlink = &lt;span style="color: #0000ff"&gt;this&lt;/span&gt;.Control &lt;span style="color: #0000ff"&gt;as&lt;/span&gt; HyperLink;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (hyperlink == &lt;span style="color: #0000ff"&gt;null&lt;/span&gt;)
            {
                &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Render(writer);
                &lt;span style="color: #0000ff"&gt;return&lt;/span&gt;;
            }

            &lt;span style="color: #008000"&gt;// This code is copied from HyperLink.RenderContents (using&lt;/span&gt;
            &lt;span style="color: #008000"&gt;// Reflector). References to "this" have been changed to&lt;/span&gt;
            &lt;span style="color: #008000"&gt;// "hyperlink", and we have to render the begin and end tags.&lt;/span&gt;
            &lt;span style="color: #0000ff"&gt;string&lt;/span&gt; imageUrl = hl.ImageUrl;
            &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (imageUrl.Length &amp;gt; 0)
            {
                &lt;span style="color: #008000"&gt;// Let the HyperLink render its begin tag&lt;/span&gt;
                hyperlink.RenderBeginTag(writer);

                Image image = &lt;span style="color: #0000ff"&gt;new&lt;/span&gt; Image();

                &lt;span style="color: #008000"&gt;// I think the next line is the bug. The URL gets&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// resolved here, but the Image.UrlResolved property&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// doesn't get set. So another attempt to resolve the&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// URL is made in Image.AddAttributesToRender. It's in&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// the callstack above that method that the exception&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// or improperly resolved URL happens.&lt;/span&gt;
                &lt;span style="color: #008000"&gt;//image.ImageUrl = base.ResolveClientUrl(imageUrl);&lt;/span&gt;
                image.ImageUrl = imageUrl;

                imageUrl = hl.ToolTip;
                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (imageUrl.Length != 0)
                {
                    image.ToolTip = imageUrl;
                }

                imageUrl = hl.Text;
                &lt;span style="color: #0000ff"&gt;if&lt;/span&gt; (imageUrl.Length != 0)
                {
                    image.AlternateText = imageUrl;
                }

                image.RenderControl(writer);

                &lt;span style="color: #008000"&gt;// Wrap up by letting the HyperLink render its end tag&lt;/span&gt;
                hyperlink.RenderEndTag(writer);
            }
            &lt;span style="color: #0000ff"&gt;else&lt;/span&gt;
            {
                &lt;span style="color: #008000"&gt;// HyperLink.RenderContents handles a couple of other&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// cases if its ImageUrl property hasn't been set. We&lt;/span&gt;
                &lt;span style="color: #008000"&gt;// delegate to that behavior here.&lt;/span&gt;
                &lt;span style="color: #0000ff"&gt;base&lt;/span&gt;.Render(writer);
            }
        }
    }&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;Next we need to tell the web site to use the ControlAdapter, this is done by creating a .&lt;em&gt;browser&lt;/em&gt; file in the &lt;em&gt;App_Browsers&lt;/em&gt; folder:&lt;/p&gt;

&lt;div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4"&gt;
  &lt;pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; height: 145px; background-color: #f4f4f4; border-bottom-style: none"&gt;&amp;lt;browsers&amp;gt;
    &amp;lt;browser refID=&lt;span style="color: #006080"&gt;"Default"&lt;/span&gt;&amp;gt;
        &amp;lt;controlAdapters&amp;gt;
            &amp;lt;adapter controlType=&lt;span style="color: #006080"&gt;"System.Web.UI.WebControls.HyperLink"&lt;/span&gt;
                     adapterType=&lt;span style="color: #006080"&gt;"MyProject.HyperLinkControlAdapter"&lt;/span&gt; /&amp;gt;
        &amp;lt;/controlAdapters&amp;gt;
    &amp;lt;/browser&amp;gt;
&amp;lt;/browsers&amp;gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt;And that's it, no more bug!&lt;/p&gt;

&lt;p&gt;Worryingly &lt;a title="Microsoft" href="http://www.microsoft.com" target="_blank"&gt;Microsoft&lt;/a&gt; were first told about the &lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=235385&amp;amp;wa=wsignin1.0" target="_blank"&gt;bug&lt;/a&gt; in November 2006, yet in January 2007 set it's status to '&lt;em&gt;Closed (won't fix)&lt;/em&gt;'. Thankfully there is a nice fix/work-around.&lt;/p&gt;

&lt;p&gt;Click &lt;a href="http://aspnet.4guysfromrolla.com/articles/013008-1.aspx" target="_blank"&gt;here&lt;/a&gt; to read the 4guysfromRolla.com article. &lt;/p&gt;&lt;img src="http://blogs.interakting.co.uk/brad/aggbug/285.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Brad</dc:creator>
            <guid>http://blogs.interakting.co.uk/brad/archive/2008/05/20/URL-Rewriting-ASP.NET-HyperLink-ImageUrl-Bug.aspx</guid>
            <pubDate>Tue, 20 May 2008 08:12:28 GMT</pubDate>
            <wfw:comment>http://blogs.interakting.co.uk/brad/comments/285.aspx</wfw:comment>
            <comments>http://blogs.interakting.co.uk/brad/archive/2008/05/20/URL-Rewriting-ASP.NET-HyperLink-ImageUrl-Bug.aspx#feedback</comments>
            <wfw:commentRss>http://blogs.interakting.co.uk/brad/comments/commentRss/285.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>