Posts

Showing posts from 2012
C# .Net - Set and Clear text in a Text Box using Javascript onfocus and on blur
<asp:TextBoxID="SearchBox"Text="Search here..."runat="server"class="SearchBoxFP"onfocus="javascript: if(this.value == 'Search here...'){ this.value = ''; }"onblur="javascript: if(this.value == ''){ this.value = 'Search here...'; }"></asp:TextBox>

Umbraco, XSLT, Display a Linked Email, Mailto in a Template from a Field in a DocType

The example below shows you how to display a linked/mailto email address in an Umbraco Template using insertTextBefore and insertTextAfter.

  <p><strong>Email Address:</strong>
<umbraco:Item field="emailAddess" insertTextBefore="&lt;a href=&quot;mailto:" insertTextAfter="&quot;&gt;" runat="server"></umbraco:Item>
  <umbraco:Item field="emailAddess" insertTextBefore="" insertTextAfter="&lt;/a&gt;" runat="server"></umbraco:Item>
  </p>

Umbraco = XSLT - Site Map - Exclude Certain Doctypes from Site Map

The example XSLT below shows you how to exclude certain nodes, based on their document type.  The important bit is highlighted.

This is done by modifying the built in XSLT Site Map that comes with Umbraco, just replace the DocType numbers in the highlighted section to get this to work.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets=&quo…

Umbraco - XSLT - List Sub Pages from a Specific Node, by Node Id

The following Umbraco XSLT list all sub pages from a specific Node using node ID.  The important bit is Highlighted.  

1)  umbraco.library:GetXmlNodeById(1062) <-- list all sub pages of nodeId 62.

2) You could replace this line above with something like this: umbraco.library:GetXmlNodeById($currentPage/chooseSubPagesToList)

and in your DocType, there would be a contentPicker called 'chooseSubPagesToList.


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Ex…

Umbraco: Enable Blockquotes in Tinymc Richtext Editor

Here is how to enable Blockquotes in Umbraco Tynymce Rich Text Editor:

1) In the folder "config" there is a file called "tinyMceConfig.config".

Add the following lines in the <command> section:

<command>
<umbracoAlias>Blockquote</umbracoAlias>
<icon>images/editor/quote.gif</icon>
<tinyMceCommand value="" userInterface="false" frontendCommand="blockquote">blockquote</tinyMceCommand>
<priority>45</priority>
</command>

Note: the line highlighted  points to an image that the user will see.  In my install this was a stop sign!  You may want to overwrite the file with something more appropriate (such as a quote).

2) In Umbraco, goto --> Developer --> Data Types --> RichtextEditor and tick the tick box for the Blockquotes.

The end user should now have blockquote functionality in there richtext editor.


Umbraco .NET C# Usercontrol Permenant Redirect to Parent Node

This is the Code behind file to permanantly redirect to a parent node in Umbraco.
There is no need to have any controls on the .asxp page.


Step 1: Create a .Net User Control called: "RedirectToPARENTnode.aspx"

Step 2: Paste the code in to the code behind file (.cs):

(important bits highlighted in yellow)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco;
using umbraco.presentation.nodeFactory;
namespace MyUserControls.Usercontrols
{
    public partial class RedirectToPARENTnode : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {  
            //MD 06/08/2012

//get the current node
            Node currentPage = Node.GetCurrent();


//get the parent node
            Node parentPage = currentPage.Parent;

//redirect to parent node
            Response.RedirectPermanent(parentPage.Url);
        }
    }
}

Umbraco - Macro -XSLT - Flash Audio Player

Umbraco - Macro -XSLT - Flash Audio Player
To create a Flash based Audio Player for Umbraco, that will allow users to choose their own audio file, is easily done in 3 steps:

Step 1). Find a Flash Audio Player you like.

I used this one: http://flash-mp3-player.net/players/mini/generator/ , it is clean and simple and is used in the code below. 

There are a lot of others that are easily integrated with the code below: http://savedelete.com/top-25-best-free-online-music-players-for-your-websites-or-blogs.html

Step 2). Upload the Audio Player to your site

Upload the Audio Player to your folder structure. In the XSLT below the file is being referenced in a folder called "audioplayer".

Step 3) Create a XSLT file with a relate Macro.
A: Paste in this code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.o…

Umbraco - C# - Redirect a Umbraco Page to an external web site.

Umbraco - C# - How to Redirect a Umbraco Page to an external web site. Two create a redirect from a Umbraco page to an exteral site you need to:   (this is very simple)

 Step 1) Add the page to Umbraco that you want to rediect. (You may want to Hide this page from navigation)

 Step 2) Create a new Web Form in C# Visual Studio
     (this web form will be placed in the route of the site)

 Step 3) Update the Web Config to include the new file mentioned in step 2
     (or you will get a Server error in appliaction)

 Step 4) Add a Url redirect to the UrlRewriting.config,  from the Umbraco page (created in step 1), to the web form (created in step 2).

Step 2: Here is the C# Code (my-redirect-example.aspx) form for step 2: (it is basically a blank form)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="my-redirect-example.aspx.cs" Inherits="my_redirect_example" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &qu…

Umbrcao - Macro - .Net - c# - Create a one time Pop Up in Umbraco using c# to display a message about cookies

Umbrcao - Macro - .Net - c# - Create a one time Pop Up in Umbraco using c# to display a message about cookies
Two create a One time pop up in umbraco to display a message, For example to warn that your site uses cookies, you need to.

1) Create a .Net user Control.
2) Add the .Net user Control to Umbraco Macros
3) Add the Macro to your Main Page Template, so that it displays on ever page.

Here are two methods for doing the one time pop up.  

The first method displays on every page until the user clicks "Click here to remove this message".  Clicking on "More information about cookies" will take them to the a page displaying your Privacy section, but will not remove the message.

The Second method displayed once and the user does not have to click anything. The message will appear on any page the user first lands on and then not be shown again.

Method 1 For Creating a One time Pop up warning about Cookies being used: 1) Create a user control called "WeUseCooki…

Umbraco - Google Maps - XSLT - Macro

The Following Macro allows you to insert a Google Map on any Umbraco Page:


1) Create a XSLT file and accopanying Macro called "GoogleMap.xslt":

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:CWS.Twitter="urn:CWS.Twitter"
  exclude-result-prefixes="msxml umbraco.library Exslt.…

Umbraco - RSS Feed for every page.

Part 1: Create A XSLT Macro for RSS Feeds:

a) Create a new XSLT Macro and Select 'RSS Feed' for the template.  Call it RSS.

b) Ammed the line that starts <xsl:variable name="SiteURL" to what ishighlighted below to create a feed on every page:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:rssdatehelper="urn:rssdatehelper"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:content="http://purl.org/rss/1.0/modules/content/"
  xmlns:msxml="urn:schemas-microsoft-com:xslt"
  xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.…

Umbraco - Richtext TinyMCE editor not showing or disappeared in the Contect Section

1)  Test: if you change the property Type in your DocType to MultiTextBox and go back you should now see the HTML version of your content.  Now, change the Type Back to a RichTextEditor.

2) Dowload another version of Umbraco, or find another install of Umbraco from a live site.

3) Copy the tinyMceConfig.config and write over the one in your broken Umbraco instance. The file is in the Folder website rout--> Config

4) Test the Site

5) If that has not sorted it, copy the folder tinymce3 (dependant on version) from your working version and overwrite the folder in your broken version.   The folder can be found in: web site rout--> umbraco_client

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version

Vimeo Uneversal Player is cross platform compatiable, and uses IFrames, so you need a Macro to Embedd a video from Vimeo in to Umbraco:

Part A: Create the XSLT File and Macro  (If you want to use Razor instead of xslt, the Razor code is at the bottom of this post)

1) Create a New Clean XSLT File and tick Create Macro.

2) Give the Macro a Name, such as: Vimeo IFrame Embedd for Vimeo Universal Player

3) Paste in the following Code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxml="urn:schemas-microsoft-com:xslt"
    xmlns:umbraco.library="urn:umbraco.library"
    exclude-result-prefixes="msxml umbraco.library">

<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/…

Umbraco - XSLT - Create a link using a Node Number.

In Umbraco XSLT you can create a link using a node number, instead of the actual node name / page url.  This can help when you may be creating static code to link to a page.  Using the node number means, if a user changes the name of the page, the link will not break!

1) So, instead of having something like this on your XSLT:

<li><a href="news.aspx" title="News">View All News</a></li>

2) You would have this: (Using the Node Number in a Link)
<li><a href="1569.aspx" title="News">View All News</a></li>

However, this will show 1596.aspx in the address bar.

3) So, use the following to show the proper url, such as news.aspx you would use the Local Link property in Umbraco:
<li><a href="/{locallink:1569.aspx}" title="News">View All News</a></li>
(You can get the node number of a page by hovering over it in Umbraco).


Other examples:
<xsl:value-of select="umbr…

.Net C# Date and Time functions and Displaying the Month using a case statment.

//Note: Literal1 refers to a Literal Control that needs to be created on your form.

        protected void dateAndTime()
        {
            // Create a Time Object
            DateTime myTime = DateTime.Now;
            // Display the Year
            Literal1.Text = "The Year is: " + myTime.Year;

            // Display the Time
            Literal1.Text += "<br />  The Time is: ";
            Literal1.Text += myTime.Hour + ":" + myTime.Minute + ":" + myTime.Second;

            // Display the Month
            Literal1.Text += "<br /> The Month is: ";
            String thisMonth;
            thisMonth = getMonth(myTime.Month); // Call the Month Function
            Literal1.Text += myTime.Month + " (" + thisMonth + ")";

        }

        String  getMonth(int monthIn)
        {
            int caseSwitch = monthIn;
            string monthOut;
            switch (caseSwitch)
            {
               …

.Net Web Config File Enable Application Tracing for Remote. Web

1).  In the <system.web> part of the Web.Config

2) Paste in the following:
 <trace pageOutput="false" requestLimit="10" enabled="true" localOnly="false" traceMode="SortByTime" mostRecent="true"/>

.NET C# HtmlEncode and HtmlEncode - Turn a String in to Valid HTML - Turn valid HTML In to a normal String. Web

// Turn a String in to Valid HTML
        var myVaildHtml = Server.HtmlEncode("blah & blah");  //  Will turn the & into &amp;
        Response.Write(myVaildHtml);

        //Turn valid HTML In to a normal String
        var myNormalString = Server.HtmlDecode(myVaildHtml);  // Will reverse the &amp; back to &
        Response.Write(myNormalString);

.NET C# Display a Text File - TransmitFile - In the Browser. Web

protected void transmitTextFile()
    {
        Response.TransmitFile("C:\\Copies\\Temp.txt");
    }

.NET C#, Permanent 301 Redirect, Temporary 302 Redirect. Web

protected void permanentRedirect ()
    {
        // 302 A PERMANENT REDIRECT
        Response.RedirectPermanent("http://www.markdownie.me.uk/");
    }

    protected void temporaryRedirect()
    {
        // 301 A TEMPORARY REDIRECT
        Response.Redirect("http://www.markdownie.me.uk/");
    }

.Net C# Get last URL, Get Current URL. Web

protected void displayUrlInfo ()
    {
        Response.Write("<br /> Request.Url - Current URL: " + Request.Url);
        Response.Write("<br /> Request.UrlReferer - URL you Came From: " + Request.UrlReferrer);  

    }

.Net c# Get or Display Browser Information. Web

protected void displayBrowserInfo ()
    {
        Response.Write("<br /> Browser: " + Request.Browser.Browser);
        Response.Write("<br /> Version: " + Request.Browser.Version);
        Response.Write("<br /> Cookies Enabled:" + Request.Browser.Cookies);
        Response.Write("<br /> Javascript Version: " + Request.Browser.JScriptVersion);   
    }

.Net Dynamicaly Create and Remove a Control / Object, such as a button. Web

private void CreateControls()
    {
        // Create a New Button
        Button myButton = new Button();
        // Give the Button Some Properties
        myButton.Text = "A Dynamicaly Created Button";
        // Add Button to PlaceHolder
        // ** NOTE: The Planel must Exist in your design view
        Panel1.Controls.Add(myButton);

        }



    private void RemoveButton()
    {
        // Search for the button in the Page Controls Collection
        Button foundButton = (Button)Page.FindControl("myButton");

        // Remove the Button
        if (foundButton != null)
        {
            foundButton.Parent.Controls.Remove(foundButton);
        }
    }

.Net C# Dynamicaly Creating Page.Header Title, Keywords and Description. Web

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Accessibility;publicpartialclass_Default : System.Web.UI.Page{

{
Page.Header.Title =
protectedvoid Page_Load(object sender, EventArgs e)"Dynamicaly Titled Page";// VERSION 1: You can use Page.MetaDescription and Page.MetaKeywordsPage.MetaDescription =
Page.MetaKeywords =
"Dynamicaly Created Meta Data Description";"Dynamic, Created, Keywords";// VERSION 2: or use Page.Header.Keywords and Page.Header.DescriptionPage.Header.Keywords =
Page.Header.Description =
}
}"More, Dynamic, Keywords";"More, Dynamic, Created, Keywords";

.Net C# write out all the controls that appear on your page. Web.

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Accessibility;publicpartialclass_Default : System.Web.UI.Page{

{
protectedvoid Page_Load(object sender, EventArgs e)// Start Examning all the ControlsDisplayControl(Page.Controls, 0);
Response.Write(


}


{

{
"<hr /");privatevoid DisplayControl(ControlCollection controls, int depth)foreach (Control control in controls)// Use the depth paramater to indent the control tree.Response.Write(
new

.NET C# Page Flow. Web

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Accessibility; publicpartialclass_Default : System.Web.UI.Page{

{

{
lblInfi.Text = (
}

}

{
lblInfi.Text +=
}

{
lblInfi.Text +=
}

{protectedvoid Page_Load(object sender, EventArgs e)if (!IsPostBack)"<b>This is the 1st time this page has been loaded.</b><br />");privatevoid Page_Init(object sender, EventArgs e)"Page.Init Event Handled.<br />";privatevoid Page_PreRender(object sender,