<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Frederik Vig - ASP.NET developer &#187; Code Snippet</title>
	<atom:link href="http://www.frederikvig.com/category/code-snippet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 14:08:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Adding different CSS classes when using the EPiServer PageTree control</title>
		<link>http://www.frederikvig.com/2010/02/adding-different-css-classes-when-using-the-episerver-pagetree/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=adding-different-css-classes-when-using-the-episerver-pagetree</link>
		<comments>http://www.frederikvig.com/2010/02/adding-different-css-classes-when-using-the-episerver-pagetree/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 23:26:49 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1101</guid>
		<description><![CDATA[Another little quick tip. I was browsing the EPiServer World forum and came across a common question. by David Green I am using the EpiServer:PageTree control to generate a nested &#60;ul&#62;&#60;li&#62; list in the format below. However I am also using a dropdown menu system called UDM which requires that the class and id &#8220;udm&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Another little quick tip. I was browsing the <a href="http://world.episerver.com/Forum/">EPiServer World forum</a> and came across a common <a href="http://world.episerver.com/Templates/Forum/Pages/Thread.aspx?id=37261&#038;epslanguage=en">question</a>. </p>
<blockquote><p>
<cite>by <a href="http://world.episerver.com/System/Users-and-profiles/Community-Profile-Card/?encryptedcurrentid=gH4Eg3C9NkmFoe0X/KzaZGdD9Rc1oiLE">David Green</a></cite></p>
<p>I am using the EpiServer:PageTree control to generate a nested &lt;ul&gt;&lt;li&gt; list in the format below.</p>
<p>However I am also using a dropdown menu system called UDM which requires that the class and id &#8220;udm&#8221; are on the first &lt;ul&gt; tag.</p>
</blockquote>
<p>The container object of the PageTree controller exposes the Indent property that we can use for this. Below is a simple example of how to add a CSS class to the first ul in your list (code is based on SubMenu.ascx from the EPiServer Public Templates package).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Control Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> EnableViewState<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;False&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SubMenu.ascx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;EPiServer.Templates.Public.Units.Static.SubMenu&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>EPiServer<span style="color: #008000;">:</span>PageTree ShowRootPage<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Menu&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>IndentTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>ul <span style="color: #008000;">&lt;%</span><span style="color: #008080;"># AddCssClassToFirstLevel(Container.Indent, &quot;udm&quot;) %&gt;&gt;</span>
    <span style="color: #008000;">&lt;/</span>IndentTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemHeaderTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>li<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemHeaderTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>EPiServer<span style="color: #008000;">:</span>Property PropertyName<span style="color: #008000;">=</span><span style="color: #666666;">&quot;PageLink&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>SelectedItemTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>EPiServer<span style="color: #008000;">:</span>Property CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;selected&quot;</span> PropertyName<span style="color: #008000;">=</span><span style="color: #666666;">&quot;PageName&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;/</span>SelectedItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemFooterTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>li<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemFooterTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>UnindentTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>ul<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>UnindentTemplate<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>EPiServer<span style="color: #008000;">:</span>PageTree<span style="color: #008000;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web.WebControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> EPiServer.<span style="color: #0000FF;">Templates</span>.<span style="color: #0600FF;">Public</span>.<span style="color: #0000FF;">Units</span>.<span style="color: #0600FF;">Static</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> SubMenu <span style="color: #008000;">:</span> UserControlBase
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> MenuList _menuList<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Gets or sets the data source for this control</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">public</span> MenuList MenuList
        <span style="color: #000000;">&#123;</span>
            get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _menuList<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
            set <span style="color: #000000;">&#123;</span> _menuList <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span><span style="color: #000000;">System</span>.<span style="color: #0000FF;">EventArgs</span> e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnLoad</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>MenuList <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            Menu.<span style="color: #0000FF;">PageLink</span> <span style="color: #008000;">=</span> MenuList.<span style="color: #0000FF;">OpenTopPage</span><span style="color: #008000;">;</span>
            Menu.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #FF0000;">string</span> AddCssClassToFirstLevel<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> level, <span style="color: #FF0000;">string</span> cssClassName<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>level <span style="color: #008000;">==</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class=<span style="color: #008080; font-weight: bold;">\&quot;</span>{0}<span style="color: #008080; font-weight: bold;">\&quot;</span>&quot;</span>, cssClassName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>We can easily add more complex logic. We also have access to the HasChildren property, which tells us if the active page has any children.</p>
<p>Hope this helps.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/08/episerver-web-controls-menulist-and-pagetree/" rel="bookmark" title="August 16, 2009">EPiServer web controls: MenuList and PageTree</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-4-creating-the-standard-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 13, 2009">Part 4: Creating the standard page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/" rel="bookmark" title="November 11, 2009">The SelectedTemplate and duplicate code</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-property/" rel="bookmark" title="July 5, 2009">EPiServer web controls: Property</a></li>
<li><a href="http://www.frederikvig.com/2010/04/listcontrol-appenddatabounditems-and-databind/" rel="bookmark" title="April 19, 2010">ListControl AppendDataBoundItems and DataBind</a></li>
</ul>
<p><!-- Similar Posts took 12.174 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/02/adding-different-css-classes-when-using-the-episerver-pagetree/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Sending confirmation email to the user when using EPiServer XForms</title>
		<link>http://www.frederikvig.com/2009/10/sending-confirmation-email-to-the-user-when-using-episerver-xforms/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sending-confirmation-email-to-the-user-when-using-episerver-xforms</link>
		<comments>http://www.frederikvig.com/2009/10/sending-confirmation-email-to-the-user-when-using-episerver-xforms/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 15:08:25 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=296</guid>
		<description><![CDATA[Plenty of websites have contact forms or other forms that users fills out to either make a request or provide feedback. This is something that many sites use instead of making their email address public available. To avoid receiving to much spam. The thing that I don&#8217;t like about these forms is that mostly I [...]]]></description>
			<content:encoded><![CDATA[<p>Plenty of websites have contact forms or other forms that users fills out to either make a request or provide feedback. This is something that many sites use instead of making their email address public available. To avoid receiving to much spam. The thing that I don&#8217;t like about these forms is that mostly I don&#8217;t get any confirmation after I&#8217;ve filled it out. </p>
<p>This is also true when using EPiServer XForms. When creating a new form the editor can choose between saving the form data in the database, emailing it, or doing both. Sending a confirmation email to the user is not a choice. </p>
<h3>Example</h3>
<p>If we take a look at the documentation &#8211; <a href="http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-5/EPiServer-CMS-5-R2-SP2/Developing-with-XForms/">Developing with XForms</a> &#8211; we see that we have the <a href="http://sdk.episerver.com/library/cms6/html/E_EPiServer_XForms_WebControls_XFormControl_AfterSubmitPostedData.htm">AfterSubmitPostedData event</a> that we can use to add the extra logic we need <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Okay lets open up our EPiServer project in Visual Studio and go to the Global.asax.cs file. Here we see the different methods being attached to various XForm events.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> XForm_ControlSetup<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    XFormControl control <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>XFormControl<span style="color: #000000;">&#41;</span>sender<span style="color: #008000;">;</span>
&nbsp;
    control.<span style="color: #0000FF;">BeforeLoadingForm</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> LoadFormEventHandler<span style="color: #000000;">&#40;</span>XForm_BeforeLoadingForm<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    control.<span style="color: #0000FF;">ControlsCreated</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #000000;">&#40;</span>XForm_ControlsCreated<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    control.<span style="color: #0000FF;">BeforeSubmitPostedData</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> SaveFormDataEventHandler<span style="color: #000000;">&#40;</span>XForm_BeforeSubmitPostedData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    control.<span style="color: #0000FF;">AfterSubmitPostedData</span> <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> SaveFormDataEventHandler<span style="color: #000000;">&#40;</span>XForm_AfterSubmitPostedData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Lets go down to the XForm_AfterSubmitPostedData method. Before we can start coding we need to figure out a way to get the users email address. If this is a community site where users register and provide this information we can just get it from there. But if not we need them to provide it for us. The easiest way is to use a TextBox where the user can type in their email address. To be able to recognize this TextBox in our code we need to use the same name in every form that needs this functionality. </p>
<p>In the code below I&#8217;ve hard coded the TextBox name (UserEmail), but you can make it more flexible by storing it in a Property or the web.config file.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> XForm_AfterSubmitPostedData<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, SaveFormDataEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var control <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>XFormControl<span style="color: #000000;">&#41;</span>sender<span style="color: #008000;">;</span>
	var pageBase <span style="color: #008000;">=</span> control.<span style="color: #0000FF;">Page</span> <span style="color: #0600FF;">as</span> PageBase<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #FF0000;">string</span> emailaddress <span style="color: #008000;">=</span> e.<span style="color: #0000FF;">FormData</span>.<span style="color: #0000FF;">GetValue</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;UserEmail&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>emailaddress<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		e.<span style="color: #0000FF;">FormData</span>.<span style="color: #0000FF;">MailTo</span> <span style="color: #008000;">=</span> emailaddress<span style="color: #008000;">;</span>
		EmailHelper.<span style="color: #0000FF;">SendUserEmail</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">FormData</span>, pageBase.<span style="color: #0000FF;">CurrentPage</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>control.<span style="color: #0000FF;">FormDefinition</span>.<span style="color: #0000FF;">PageAfterPost</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		PageData redirectPage <span style="color: #008000;">=</span> DataFactory.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">GetPage</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> PageReference<span style="color: #000000;">&#40;</span>control.<span style="color: #0000FF;">FormDefinition</span>.<span style="color: #0000FF;">PageAfterPost</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		control.<span style="color: #0000FF;">Page</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">Redirect</span><span style="color: #000000;">&#40;</span>redirectPage.<span style="color: #0000FF;">LinkURL</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		return<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">//After the form has been posted we remove the form elements and add a &quot;thank you message&quot;.</span>
	control.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	Label label <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	label.<span style="color: #0000FF;">CssClass</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;thankyoumessage&quot;</span><span style="color: #008000;">;</span>
	label.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> LanguageManager.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">Translate</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/form/postedmessage&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	control.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>label<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The EmailHelper class with the SendUserEmail method.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Specialized</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net.Mail</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.XForms</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Util</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> EmailHelper
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">bool</span> SendUserEmail<span style="color: #000000;">&#40;</span>XFormData formData, PageData currentPage<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>formData <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                var message <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MailMessage<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                var mailFrom <span style="color: #008000;">=</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;no-reply@{0}&quot;</span>, HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">Url</span>.<span style="color: #0000FF;">Host</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>formData.<span style="color: #0000FF;">MailFrom</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    mailFrom <span style="color: #008000;">=</span> formData.<span style="color: #0000FF;">MailFrom</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                message.<span style="color: #0000FF;">From</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> MailAddress<span style="color: #000000;">&#40;</span>mailFrom<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                message.<span style="color: #0000FF;">To</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>formData.<span style="color: #0000FF;">MailTo</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                message.<span style="color: #0000FF;">Subject</span> <span style="color: #008000;">=</span> formData.<span style="color: #0000FF;">MailSubject</span><span style="color: #008000;">;</span>
                message.<span style="color: #0000FF;">IsBodyHtml</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                message.<span style="color: #0000FF;">BodyEncoding</span> <span style="color: #008000;">=</span> Encoding.<span style="color: #0000FF;">UTF8</span><span style="color: #008000;">;</span>
&nbsp;
                var body <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;html&gt;&lt;body&gt;&lt;table border=<span style="color: #008080; font-weight: bold;">\&quot;</span>0<span style="color: #008080; font-weight: bold;">\&quot;</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                NameValueCollection postedValues <span style="color: #008000;">=</span> formData.<span style="color: #0000FF;">GetValues</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key <span style="color: #0600FF;">in</span> postedValues<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;tr&gt;&lt;td&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>key<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;: &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/td&gt;&lt;td&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>postedValues<span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/td&gt;&lt;/tr&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                body.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                message.<span style="color: #0000FF;">Body</span> <span style="color: #008000;">=</span> body.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                var smtp <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SmtpClient<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                smtp.<span style="color: #0000FF;">Send</span><span style="color: #000000;">&#40;</span>message<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>Exception ex<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// Remember to do some logging here..</span>
                <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Since we both have the XFormData object and the CurrentPage PageData object we can do a lot more than what I&#8217;ve illustrated in the code above. You can for instance create an email template in EPiServer that editors can edit that you use to send to as a standard &#8220;thank you email&#8221; to the user.</p>
<h3>Testing</h3>
<p>To test this code create a new XForm and add a TextBox with the name UserEmail. </p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/xforms/xform-window.png"><img src="http://www.frederikvig.com/wp-content/uploads/xforms/xform-window.png" width="400" alt="" /></a></p>
<p>Try sending it, you should receive an email with the form data (form fields and their values). Remember that for this to work you also need to configure the SMTP settings in your web.config file. </p>
<p>When developing locally, I usually set it to point to a local directory that the emails get sent to.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mailSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;smtp</span> <span style="color: #000066;">deliveryMethod</span>=<span style="color: #ff0000;">&quot;SpecifiedPickupDirectory&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
                <span style="color: #808080; font-style: italic;">&lt;!-- You need to give the Network Service or ASPNET user modify permissions on your directory  --&gt;</span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;specifiedPickupDirectory</span> <span style="color: #000066;">pickupDirectoryLocation</span>=<span style="color: #ff0000;">&quot;E:\temp\maildrop&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/smtp<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mailSettings<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You should now receive an email that looks something like this.</p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/xforms/email.png"><img src="http://www.frederikvig.com/wp-content/uploads/xforms/email.png" width="400" alt="" /></a></p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/xforms/xforms.zip">Download the code</a></p>
<h3>Other resources</h3>
<ul>
<li><a href="http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-5/EPiServer-CMS-5-R2-SP2/Developing-with-XForms/">Developing with XForms</a></li>
<li><a href="http://labs.episerver.com/en/Blogs/Mari-Jorgensen/Dates/112298/5/Overriding-subscription-email-formatting/">Overriding subscription email formatting</a></li>
<li><a href="http://labs.episerver.com/en/Blogs/Linus-Ekstrom1/Dates/2009/8/Altering-the-XForm-email-body-to-make-it-look-more-like-the-actual-form/">Altering the XForm email body to make it look more like the actual form</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/05/creating-a-contact-form-with-asp-net-mvc/" rel="bookmark" title="May 13, 2010">Creating a contact form with ASP.NET MVC</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-6-creating-the-xform-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 19, 2009">Part 6: Creating the XForm page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-5-creating-the-search-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 16, 2009">Part 5: Creating the search page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-property/" rel="bookmark" title="July 5, 2009">EPiServer web controls: Property</a></li>
<li><a href="http://www.frederikvig.com/2009/06/using-multiple-forms-on-an-asp-net-web-forms-page/" rel="bookmark" title="June 21, 2009">Using multiple forms on an ASP.NET web forms page</a></li>
</ul>
<p><!-- Similar Posts took 12.053 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/10/sending-confirmation-email-to-the-user-when-using-episerver-xforms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating a Custom EPiServer Paging Control</title>
		<link>http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=creating-a-custom-episerver-paging-control</link>
		<comments>http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/#comments</comments>
		<pubDate>Sun, 20 Sep 2009 13:20:59 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=224</guid>
		<description><![CDATA[Earlier I wrote about the PageList control from EPiServer, I mentioned in that post that the markup that the PagingControl renders is not the best. For instance it will not work without JavaScript enabled on the client (for search engines the links wont work). I therefor decided to create my own. To start with I [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier I wrote about the <a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/">PageList control</a> from EPiServer, I mentioned in that post that the markup that the <a href="http://sdk.episerver.com/library/cms6/html/AllMembers_T_EPiServer_Web_WebControls_PagingControl.htm">PagingControl</a> renders is not the best. For instance it will not work without JavaScript enabled on the client (for search engines the links wont work). I therefor decided to create my own.</p>
<p>To start with I went to the <a href="http://sdk.episerver.com/library/cms6/">EPiServer SDK</a> to have a look at the <a href="http://sdk.episerver.com/library/cms6/html/T_EPiServer_Web_WebControls_PagingControl.htm">PagingControl class</a>. Here I was able to see the namespace and what .dll file it lives in (EPiServer.dll). I then opened up <a href="http://www.red-gate.com/products/reflector/">Reflector</a>, to inspect EPiServer.dll and have a closer look at the code. </p>
<p>Description of Reflector by Red Gate.</p>
<blockquote>
<p>.NET Reflector enables you to easily view, navigate, and search through, the class hierarchies of .NET assemblies, even if you don&#8217;t have the code for them. With it, you can decompile and analyze .NET assemblies in C#, Visual Basic, and IL.</p>
</blockquote>
<p>To find the PagingControl class you can either use the search feature or navigate the namespaces. </p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/paging/reflector.png"><img src="http://www.frederikvig.com/wp-content/uploads/paging/reflector.png" width="500" alt="PagingControl class with Reflector" /></a></p>
<p>The great thing is that all the methods are virtual which means that we can override them <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>Start by creating a new class and inherit from PagingControl (remember to add using EPiServer.Web.WebControls;).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.HtmlControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web.WebControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Classes</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomPager <span style="color: #008000;">:</span> PagingControl
    <span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then create a new page template with a PageList control.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Page.aspx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;FV.Templates.FV.Pages.Page&quot;</span> MasterPageFile<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/Templates/Public/MasterPages/MasterPage.master&quot;</span> <span style="color: #008000;">%&gt;</span>
<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Content runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ContentPlaceHolderID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MainBodyRegion&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>EPiServer<span style="color: #008000;">:</span>PageList runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;pglList&quot;</span><span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>ul<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;</span>li<span style="color: #008000;">&gt;&lt;</span>EPiServer<span style="color: #008000;">:</span>Property runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> PropertyName<span style="color: #008000;">=</span><span style="color: #666666;">&quot;PageLink&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>li<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>FooterTemplate<span style="color: #008000;">&gt;</span>
            <span style="color: #008000;">&lt;/</span>ul<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;/</span>FooterTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>EPiServer<span style="color: #008000;">:</span>PageList<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Content<span style="color: #008000;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">FV.Templates.FV.Classes</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Pages</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Page <span style="color: #008000;">:</span> TemplatePage
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnLoad</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            pglList.<span style="color: #0000FF;">Paging</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
            pglList.<span style="color: #0000FF;">PageLink</span> <span style="color: #008000;">=</span> PageReference.<span style="color: #0000FF;">StartPage</span><span style="color: #008000;">;</span>
            pglList.<span style="color: #0000FF;">PagingControl</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> CustomPager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            pglList.<span style="color: #0000FF;">PagesPerPagingItem</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">2</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Notice that we set the PageList&#8217;s PagingControl property to a new instance of our CustomPager web control.</p>
<p>If you open up a browser and run the code, you&#8217;ll just get a standard PagingControl with the JavaScript and bad markup (since we haven&#8217;t overridden anything yet).</p>
<p>Lets start by adding an <a href="http://reference.sitepoint.com/html/ol">ordered list</a> for the paging items.</p>
<p>To do this we have to override the CreatePagingItems, AddSelectedPagingLink and AddUnselectedPagingLink methods.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.HtmlControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web.WebControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Classes</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomPager <span style="color: #008000;">:</span> PagingControl
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> HtmlGenericControl Container
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Translate<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> LanguageManager.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">Translate</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/webcontrols/paging/&quot;</span> <span style="color: #008000;">+</span> text<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> LinkButton AddSelectedPagingLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pagingIndex, <span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">string</span> altText<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CssClassSelected</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;title&quot;</span>, altText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">InnerText</span> <span style="color: #008000;">=</span> text<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>li<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> LinkButton AddUnselectedPagingLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pagingIndex, <span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">string</span> altText, <span style="color: #FF0000;">bool</span> visible<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var child <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CreatePagingLink</span><span style="color: #000000;">&#40;</span>pagingIndex, text, altText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            child.<span style="color: #0000FF;">CssClass</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CssClassUnselected</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> visible<span style="color: #008000;">;</span>
&nbsp;
            li.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>child<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>li<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreatePagingItems<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">int</span> pagingIndex <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemCount</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">bool</span> visible <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">bool</span> flag2 <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">&lt;</span> pagingIndex<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>pagingIndex <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoPaging</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ol&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LinkCounter</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">FirstPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">FirstPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;firstpage&quot;</span><span style="color: #000000;">&#41;</span>, visible<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">PrevPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">PrevPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;prevpage&quot;</span><span style="color: #000000;">&#41;</span>, visible<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> pagingIndex<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #008000;">==</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddSelectedPagingLink</span><span style="color: #000000;">&#40;</span>i, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;currentpage&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">else</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span>i, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;pagenumber&quot;</span><span style="color: #000000;">&#41;</span>, i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">NextPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">NextPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;nextpage&quot;</span><span style="color: #000000;">&#41;</span>, flag2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LastPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span>pagingIndex, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LastPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lastpage&quot;</span><span style="color: #000000;">&#41;</span>, flag2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I added a private property to hold my ordered list (Container), so that I can easily add child controls to it. I Also removed the calls to the AddLinkSpacing method (since we don&#8217;t need it).</p>
<p>If you browse the page you&#8217;ll see that everything is inside an ordered list now.</p>
<p>To fix the JavaScript links I created a new method CreatePagingHyperLink that will create the HyperLink control with the correct url. I Then added code in the OnInit method to get the query string and set the PageList&#8217;s CurrentPagingItemIndex property.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.HtmlControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI.WebControls</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web.WebControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Classes</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> CustomPager <span style="color: #008000;">:</span> PagingControl
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">private</span> HtmlGenericControl Container
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnInit<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnInit</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;p&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                return<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            var p <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;p&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">int</span> num<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #FF0000;">int</span>.<span style="color: #0000FF;">TryParse</span><span style="color: #000000;">&#40;</span>p, <span style="color: #0600FF;">out</span> num<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">=</span> num<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> Translate<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> LanguageManager.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">Translate</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/webcontrols/paging/&quot;</span> <span style="color: #008000;">+</span> text<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> LinkButton AddSelectedPagingLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pagingIndex, <span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">string</span> altText<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CssClassSelected</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;title&quot;</span>, altText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">InnerText</span> <span style="color: #008000;">=</span> text<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>li<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> LinkButton AddUnselectedPagingLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pagingIndex, <span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">string</span> altText, <span style="color: #FF0000;">bool</span> visible<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var li <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;li&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var child <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CreatePagingHyperLink</span><span style="color: #000000;">&#40;</span>pagingIndex, text, altText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            child.<span style="color: #0000FF;">CssClass</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CssClassUnselected</span><span style="color: #008000;">;</span>
            li.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> visible<span style="color: #008000;">;</span>
&nbsp;
            li.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>child<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>li<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> CreateUrl<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> count<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlBuilder<span style="color: #000000;">&#40;</span>HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">Url</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>UrlRewriteProvider.<span style="color: #0000FF;">IsFurlEnabled</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Global.<span style="color: #0000FF;">UrlRewriteProvider</span>.<span style="color: #0000FF;">ConvertToExternal</span><span style="color: #000000;">&#40;</span>url, <span style="color: #0600FF;">null</span>, Encoding.<span style="color: #0000FF;">UTF8</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> UriSupport.<span style="color: #0000FF;">AddQueryString</span><span style="color: #000000;">&#40;</span>url.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;p&quot;</span>, count.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">protected</span> HyperLink CreatePagingHyperLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pagingIndex, <span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">string</span> altText<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var link <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HyperLink<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LinkCounter</span><span style="color: #008000;">++;</span>
            link.<span style="color: #0000FF;">ID</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;PagingID&quot;</span> <span style="color: #008000;">+</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LinkCounter</span><span style="color: #008000;">;</span>
            link.<span style="color: #0000FF;">NavigateUrl</span> <span style="color: #008000;">=</span> CreateUrl<span style="color: #000000;">&#40;</span>pagingIndex<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            link.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> text<span style="color: #008000;">;</span>
            link.<span style="color: #0000FF;">ToolTip</span> <span style="color: #008000;">=</span> altText<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> link<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> CreatePagingItems<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">int</span> pagingIndex <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemCount</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">bool</span> visible <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">bool</span> flag2 <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">&lt;</span> pagingIndex<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>pagingIndex <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">||</span> <span style="color: #008000;">!</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoPaging</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span> <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ol&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LinkCounter</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">FirstPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">FirstPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;firstpage&quot;</span><span style="color: #000000;">&#41;</span>, visible<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">PrevPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">PrevPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;prevpage&quot;</span><span style="color: #000000;">&#41;</span>, visible<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;=</span> pagingIndex<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>i <span style="color: #008000;">==</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddSelectedPagingLink</span><span style="color: #000000;">&#40;</span>i, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;currentpage&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                    <span style="color: #0600FF;">else</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span>i, Convert.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#40;</span>i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span>Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;pagenumber&quot;</span><span style="color: #000000;">&#41;</span>, i <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span><span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">NextPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CurrentPagingItemIndex</span> <span style="color: #008000;">+</span> <span style="color: #FF0000;">1</span>, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">NextPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;nextpage&quot;</span><span style="color: #000000;">&#41;</span>, flag2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LastPagingItemText</span>.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AddUnselectedPagingLink</span><span style="color: #000000;">&#40;</span>pagingIndex, <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">LastPagingItemText</span>, Translate<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lastpage&quot;</span><span style="color: #000000;">&#41;</span>, flag2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Container</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I also added some CSS code to give you an idea of how easy it is to style and change the look.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.PagingContainer</span> ol <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.PagingContainer</span> li <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">list-style</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.PagingContainer</span> a<span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.SelectedPagingItem</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">text-decoration</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #933;">.2em</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">border</span><span style="color: #00AA00;">:</span> <span style="color: #933;">1px</span> <span style="color: #993333;">solid</span> <span style="color: #cc00cc;">#303233</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#303233</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">font-weight</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">bold</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-right</span><span style="color: #00AA00;">:</span> <span style="color: #933;">.1em</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.PagingContainer</span> <span style="color: #6666ff;">.SelectedPagingItem</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#303233</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#fff</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>The result</h3>
<p><img src="http://www.frederikvig.com/wp-content/uploads/paging/paging1.png" alt="Custom paging control" /></p>
<h3>Markup rendered</h3>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">div</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;PagingContainer&quot;</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">ol</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;SelectedPagingItem&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Current page&quot;</span>&gt;</span>1<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ctl00_MainRegion_MainContentRegion_MainBodyRegion_pglList_ctl05_PagingID4&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Page 2&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UnselectedPagingItem&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://fv/en/Test-Paging/?p=1&quot;</span>&gt;</span>2<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ctl00_MainRegion_MainContentRegion_MainBodyRegion_pglList_ctl05_PagingID5&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Page 3&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UnselectedPagingItem&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://fv/en/Test-Paging/?p=2&quot;</span>&gt;</span>3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ctl00_MainRegion_MainContentRegion_MainBodyRegion_pglList_ctl05_PagingID6&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Next page&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UnselectedPagingItem&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://fv/en/Test-Paging/?p=1&quot;</span>&gt;</span>&gt;<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
                <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ctl00_MainRegion_MainContentRegion_MainBodyRegion_pglList_ctl05_PagingID7&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Last page&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;UnselectedPagingItem&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://fv/en/Test-Paging/?p=2&quot;</span>&gt;</span>»<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
            <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">li</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">ol</span>&gt;</span>
    <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">div</span>&gt;</span></pre></div></div>

<p><a href="http://www.frederikvig.com/wp-content/uploads/paging/paging.zip">Download the code</a><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/02/adding-different-css-classes-when-using-the-episerver-pagetree/" rel="bookmark" title="February 28, 2010">Adding different CSS classes when using the EPiServer PageTree control</a></li>
<li><a href="http://www.frederikvig.com/2010/05/episerver-custom-property-with-custom-settings/" rel="bookmark" title="May 14, 2010">EPiServer Custom Property with Custom Settings</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/" rel="bookmark" title="July 20, 2009">EPiServer web controls: PageList</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2009/11/better-breadcrumb-trail/" rel="bookmark" title="November 14, 2009">Better breadcrumb trail</a></li>
</ul>
<p><!-- Similar Posts took 11.271 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Extending search field with suggestion box</title>
		<link>http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=extending-search-field-with-suggestion-box</link>
		<comments>http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 15:20:58 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=212</guid>
		<description><![CDATA[Disclaimer: In this example I&#8217;ve kept the code simple to make it easier to read and to give you an idea of how you might approach something like this with EPiServer. This code should not be used in production scenarios since it will use a lot of resources. Use at own risk . Update &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p>Disclaimer: In this example I&#8217;ve kept the code simple to make it easier to read and to give you an idea of how you might approach something like this with EPiServer. This code should not be used in production scenarios since it will use a lot of resources. Use at own risk <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<h3>Update &#8211; 12.10.2009</h3>
<p>Updated production code with a new custom filter that removes pages that the Everyone role doesn&#8217;t have access to.<br />
Also updated the Get caching method. See <a href="http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/comment-page-1/#comment-38">comments below for further details</a>.</p>
<h3>Update &#8211; 19.09.2009</h3>
<p>Added example of production code you might consider. </p>
<p>We&#8217;ve all used Google Suggest before. When you start typing a word or sentence, Google comes up with suggestions to what we might be searching for.<br />
<img src="http://www.frederikvig.com/wp-content/uploads/suggest/google-suggest.png" alt="Example of Google Suggest" /><br />
This is to help users quickly find what they want. </p>
<p>In this blog post we&#8217;re going to do the same by extending QuickSearch that ships with the EPiServer Public Templates. </p>
<p>I decided to use <a href="http://www.jquery.com/">jQuery</a> and the <a href="http://plugins.jquery.com/project/autocompletex">AutoComplete</a> plugin for this, but you can use any script you like (most are pretty similar).</p>
<h3>The result</h3>
<p><img src="http://www.frederikvig.com/wp-content/uploads/suggest/episerver-suggest.png" alt="Example of search suggest" /></p>
<h3>The Code</h3>
<p>First start by modifying the QuickSearch.ascx:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Panel runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;QuickSearchArea&quot;</span> DefaultButton<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SearchButton&quot;</span><span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Label ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SearchLabel&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> AssociatedControlID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SearchText&quot;</span> CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;hidden&quot;</span> Text<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%$ Resources: EPiServer, navigation.search %&gt;&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>TextBox ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SearchText&quot;</span> TabIndex<span style="color: #008000;">=</span><span style="color: #666666;">&quot;1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;quickSearchField&quot;</span> autocomplete<span style="color: #008000;">=</span><span style="color: #666666;">&quot;off&quot;</span> <span style="color: #008000;">/&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ImageButton ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SearchButton&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ImageUrl<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/Templates/Public/Images/MainMenuSearchButton.png&quot;</span> ToolTip<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%$ Resources: EPiServer, navigation.search %&gt;&quot;</span> CausesValidation<span style="color: #008000;">=</span><span style="color: #666666;">&quot;false&quot;</span> CssClass<span style="color: #008000;">=</span><span style="color: #666666;">&quot;quickSearchButton&quot;</span> OnClick<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Search_Click&quot;</span> <span style="color: #008000;">/&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Panel<span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>script type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/javascript&quot;</span><span style="color: #008000;">&gt;</span>
<span style="color: #008080; font-style: italic;">//&lt;![CDATA[ </span>
    $<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;#&lt;%=SearchText.ClientID %&gt;&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">autocomplete</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;/path/to/file/SearchSuggest.aspx&quot;</span>, <span style="color: #000000;">&#123;</span>
        minChars<span style="color: #008000;">:</span> <span style="color: #FF0000;">2</span>,
        max<span style="color: #008000;">:</span> <span style="color: #FF0000;">10</span>
    <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">//]]&gt; </span>
<span style="color: #008000;">&lt;/</span>script<span style="color: #008000;">&gt;</span></pre></div></div>

<p>A few things to note. I removed the default text from the TextBox and added the attribute autocomplete=&#8221;off&#8221;, this is to ensure that the users browser does not store the information (<a href="https://developer.mozilla.org/en/How_to_Turn_Off_Form_Autocompletion">How to Turn Off Form Autocompletion</a>). I then attached the AutoComplete plugin to the TextBox and changed a few of its default properties. </p>
<p>As you can see there is not much code that is needed when mostly using the default settings. You can of course do a lot more. Browse through the <a href="http://docs.jquery.com/Plugins/Autocomplete">AutoComplete plugin documentation</a> and see the <a href="http://view.jquery.com/trunk/plugins/autocomplete/demo/">demos</a> to get a few ideas.</p>
<p>Now for the main part, SearchSuggestion.aspx. This is just an empty web forms page with all the code in the code-behind:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Filters</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Security</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Pages</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> SearchSuggest <span style="color: #008000;">:</span> TemplatePage
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// #1</span>
            <span style="color: #FF0000;">string</span> query <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;q&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> limit <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;limit&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// #2</span>
                var criterias <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PropertyCriteriaCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                var queryCriteria <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PropertyCriteria
                                        <span style="color: #000000;">&#123;</span>
                                            Condition <span style="color: #008000;">=</span> CompareCondition.<span style="color: #0000FF;">StartsWith</span>,
                                            Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;PageName&quot;</span>,
                                            Value <span style="color: #008000;">=</span> query,
                                            Type <span style="color: #008000;">=</span> PropertyDataType.<span style="color: #FF0000;">String</span>,
                                            Required <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>
                                        <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                var pubCriteria <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PropertyCriteria
                                      <span style="color: #000000;">&#123;</span>
                                          Condition <span style="color: #008000;">=</span> CompareCondition.<span style="color: #0000FF;">Equal</span>,
                                          Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;PagePendingPublish&quot;</span>,
                                          Value <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                                          Type <span style="color: #008000;">=</span> PropertyDataType.<span style="color: #0000FF;">Boolean</span>,
                                          Required <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>
                                      <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                criterias.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>queryCriteria<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                criterias.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pubCriteria<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// #3</span>
                var pages <span style="color: #008000;">=</span> DataFactory.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">FindPagesWithCriteria</span><span style="color: #000000;">&#40;</span>PageReference.<span style="color: #0000FF;">StartPage</span>, criterias, CurrentPage.<span style="color: #0000FF;">LanguageBranch</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #FF0000;">int</span> tempLimit <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>limit<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">int</span> pagesCount <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// #4</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>tempLimit <span style="color: #008000;">&gt;</span> pagesCount<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    tempLimit <span style="color: #008000;">=</span> pagesCount<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// #5</span>
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> tempLimit<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>pages<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">PageName</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">NewLine</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// #6</span>
                Response.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Content-Type&quot;</span>, <span style="color: #666666;">&quot;text/html&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                Response.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<ul>
<li>In #1 we retrieve the user input and the limit (which we set earlier with the max property in QuickSearch.ascx), we then HTML encode it (something you should always do when receiving user input).</li>
<li>In #2 we build the criteria collection with our search options. We search for pages that start with what the user typed in and then make sure that only published pages are returned.</li>
<li>In #3 we do the actual searching with the <a href="http://sdk.episerver.com/library/cms6/html/Overload_EPiServer_DataFactory_FindPagesWithCriteria.htm">FindPagesWithCriteria method</a> where we also set the current language branch (only return pages in that language).</li>
<li>In #4 we make sure that we don&#8217;t have less pages than the limit, if so we set the pages count to be the limit.</li>
<li>In #5 we go through pages (PageDataCollection) and add the PageName to sb (StringBuilder).</li>
<li>In #6 we return the result back</li>
</ul>
<p>Below is the code for SearchSuggest.aspx.cs updated to use the SearchDataSource instead of FindPagesWithCriteria (this will not only search the PageName but all properties that are search able):</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.UI</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Security</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Web.WebControls</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Pages</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> SearchSuggest <span style="color: #008000;">:</span> TemplatePage
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> query <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;q&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> limit <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;limit&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                var searchDataSource <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SearchDataSource
                <span style="color: #000000;">&#123;</span>
                    SearchQuery <span style="color: #008000;">=</span> query,
                    AccessLevel <span style="color: #008000;">=</span> AccessLevel.<span style="color: #0000FF;">Read</span>,
                    PublishedStatus <span style="color: #008000;">=</span> PagePublishedStatus.<span style="color: #0000FF;">Published</span>,
                    PageLink <span style="color: #008000;">=</span> PageReference.<span style="color: #0000FF;">StartPage</span>,
                    LanguageBranches <span style="color: #008000;">=</span> CurrentPage.<span style="color: #0000FF;">LanguageBranch</span>,
                    MaxCount <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>limit<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>PageData page <span style="color: #0600FF;">in</span> searchDataSource.<span style="color: #0000FF;">Select</span><span style="color: #000000;">&#40;</span>DataSourceSelectArguments.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>page.<span style="color: #0000FF;">PageName</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">NewLine</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                Response.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Content-Type&quot;</span>, <span style="color: #666666;">&quot;text/html&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                Response.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<h3>Production code</h3>
<p>Like I said in the beginning, this code should not be used in production scenarios since it goes through the entire site searching for matching PageNames each time there is a request. </p>
<p>I&#8217;ve added some example code of how you might approach this in a production scenario. Basically I just use the FindPagesWithCriteria method to find all the pages and then store the PageName of each in an array that I then store in the cache for easy access.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Filters</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Security</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">FV.Templates.FV.Filters</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Pages</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> ProductionSearchSuggestion <span style="color: #008000;">:</span> TemplatePage
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> query <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;q&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">string</span> limit <span style="color: #008000;">=</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>Request.<span style="color: #0000FF;">QueryString</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;limit&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>query<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                var sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> pageNames<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> pageNamesCacheKey <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;AllPageNames&quot;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>Get<span style="color: #000000;">&#40;</span>pageNamesCacheKey, <span style="color: #0600FF;">out</span> pageNames<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    var criterias <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PropertyCriteriaCollection<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    var pubCriteria <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> PropertyCriteria
                    <span style="color: #000000;">&#123;</span>
                        Condition <span style="color: #008000;">=</span> CompareCondition.<span style="color: #0000FF;">Equal</span>,
                        Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;PagePendingPublish&quot;</span>,
                        Value <span style="color: #008000;">=</span> <span style="color: #0600FF;">false</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>,
                        Type <span style="color: #008000;">=</span> PropertyDataType.<span style="color: #0000FF;">Boolean</span>,
                        Required <span style="color: #008000;">=</span> <span style="color: #0600FF;">true</span>
                    <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
                    criterias.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pubCriteria<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    var pages <span style="color: #008000;">=</span> DataFactory.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">FindPagesWithCriteria</span><span style="color: #000000;">&#40;</span>PageReference.<span style="color: #0000FF;">StartPage</span>, criterias, CurrentPage.<span style="color: #0000FF;">LanguageBranch</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008000;">new</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Everyone&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>pages<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    var pagesCount <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span><span style="color: #008000;">;</span>
                    pageNames <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span>pagesCount<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> pagesCount<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        pageNames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> pages<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">PageName</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
&nbsp;
                    Add<span style="color: #000000;">&#40;</span>pageNames, pageNamesCacheKey<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #FF0000;">int</span> tempLimit <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span>limit<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                var result <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span>tempLimit<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                <span style="color: #FF0000;">int</span> resultCounter <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> pageNames.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>resultCounter <span style="color: #008000;">&lt;=</span> tempLimit <span style="color: #008000;">&amp;&amp;</span> pageNames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>query.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;&amp;</span> <span style="color: #008000;">!</span>result.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>pageNames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        result<span style="color: #000000;">&#91;</span>resultCounter<span style="color: #008000;">++</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> pageNames<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> resultCounter<span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>result<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">NewLine</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                Response.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Content-Type&quot;</span>, <span style="color: #666666;">&quot;text/html&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Response.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                Response.<span style="color: #0000FF;">End</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// Caching methods from http://johnnycoder.com/blog/2008/12/10/c-cache-helper-class/</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> Exists<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span> <span style="color: #008000;">!=</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> Get<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> key, <span style="color: #0600FF;">out</span> T value<span style="color: #000000;">&#41;</span> where T<span style="color: #008000;">:</span><span style="color: #FF0000;">class</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">try</span>
            <span style="color: #000000;">&#123;</span>
                value <span style="color: #008000;">=</span> HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span><span style="color: #000000;">&#91;</span>key<span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> T<span style="color: #008000;">;</span>
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>value <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    value <span style="color: #008000;">=</span> <span style="color: #0600FF;">default</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
            <span style="color: #0600FF;">catch</span>
            <span style="color: #000000;">&#123;</span>
                value <span style="color: #008000;">=</span> <span style="color: #0600FF;">default</span><span style="color: #000000;">&#40;</span>T<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">return</span> false<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> true<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Add<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span>T o, <span style="color: #FF0000;">string</span> key<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            HttpContext.<span style="color: #0000FF;">Current</span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">Insert</span><span style="color: #000000;">&#40;</span>
                key,
                o,
                <span style="color: #0600FF;">null</span>,
                DateTime.<span style="color: #0000FF;">Now</span>.<span style="color: #0000FF;">AddMinutes</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">3600</span><span style="color: #000000;">&#41;</span>,
                <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Caching</span></span>.<span style="color: #0000FF;">Cache</span>.<span style="color: #0000FF;">NoSlidingExpiration</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The FilterRole class</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Filters</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Filters</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FilterRole <span style="color: #008000;">:</span> IPageFilter
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> RoleName
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> roleName<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">RoleName</span> <span style="color: #008000;">=</span> roleName<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i<span style="color: #008000;">--</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">bool</span> isMatch <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
                var acl <span style="color: #008000;">=</span> pages<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ACL</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>acl <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var role <span style="color: #0600FF;">in</span> acl<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>role.<span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">RoleName</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            isMatch <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>isMatch<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    pages.<span style="color: #0000FF;">RemoveAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, FilterEventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Pages</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> ShouldFilter<span style="color: #000000;">&#40;</span>PageData page<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><a href="http://www.frederikvig.com/wp-content/uploads/suggest/SearchSuggest.zip">Download the code</a><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/06/using-multiple-forms-on-an-asp-net-web-forms-page/" rel="bookmark" title="June 21, 2009">Using multiple forms on an ASP.NET web forms page</a></li>
<li><a href="http://www.frederikvig.com/2009/10/episerver-findpageswithcriteria-and-findallpageswithcriteria/" rel="bookmark" title="October 21, 2009">EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria</a></li>
<li><a href="http://www.frederikvig.com/2009/05/aspnet-validation-and-jquery/" rel="bookmark" title="May 21, 2009">ASP.NET Validation and jQuery</a></li>
<li><a href="http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/" rel="bookmark" title="September 20, 2009">Creating a Custom EPiServer Paging Control</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-5-creating-the-search-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 16, 2009">Part 5: Creating the search page – Create an EPiServer site from scratch</a></li>
</ul>
<p><!-- Similar Posts took 13.344 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Add class attribute to body element with ASP.NET web forms and Master Pages</title>
		<link>http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=add-class-to-body-element-with-asp-net-web-forms-and-master-pages</link>
		<comments>http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 22:04:52 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=194</guid>
		<description><![CDATA[Often I have to add a class to the HTML body element. This is a little code snippet that allows you to easily do this. &#60;%@ Master Language=&#34;C#&#34; AutoEventWireup=&#34;true&#34; CodeBehind=&#34;Site1.master.cs&#34; Inherits=&#34;WebApplication1.Site1&#34; %&#62; &#160; &#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62; &#160; &#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34; &#62; &#60;head runat=&#34;server&#34;&#62; &#60;title&#62;&#60;/title&#62; &#60;asp:ContentPlaceHolder ID=&#34;head&#34; runat=&#34;server&#34;&#62; &#60;/asp:ContentPlaceHolder&#62; &#60;/head&#62; &#60;body runat=&#34;server&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>Often I have to add a class to the HTML body element. This is a little code snippet that allows you to easily do this.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Master Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;Site1.master.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;WebApplication1.Site1&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;!</span>DOCTYPE html <span style="color: #0600FF;">PUBLIC</span> <span style="color: #666666;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #666666;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>ContentPlaceHolder ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;head&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>ContentPlaceHolder<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;BodyTag&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    ...
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Add the public property BodyClass.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> BodyClass
<span style="color: #000000;">&#123;</span>
    set
    <span style="color: #000000;">&#123;</span>
        BodyTag.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;class&quot;</span>, value<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then in your .aspx, you need to make the Master Page strongly typed by adding MasterType (you can also manually cast it to the right type).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ MasterType VirtualPath<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/Site1.Master&quot;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>

<p>You&#8217;ll now have access to the Master Pages BodyClass property.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Master.<span style="color: #0000FF;">BodyClass</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;home&quot;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Or by manually casting it</span>
<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Site1<span style="color: #000000;">&#41;</span>Master<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">BodyClass</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;home&quot;</span><span style="color: #008000;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">...
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">body</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ctl00_BodyTag&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;home&quot;</span>&gt;</span>
...</pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/05/cast-from-bool-to-bool/" rel="bookmark" title="May 4, 2009">Safely Cast from bool? to bool</a></li>
<li><a href="http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/" rel="bookmark" title="August 15, 2009">Adding CSS and JavaScript files dynamically to your ASP.NET page</a></li>
<li><a href="http://www.frederikvig.com/2010/01/a-developers-guide-to-pagetypebuilder/" rel="bookmark" title="January 15, 2010">A developer&#8217;s guide to PageTypeBuilder</a></li>
<li><a href="http://www.frederikvig.com/2010/02/getting-the-page-and-episerver-currentpage-object-from-httpcontext/" rel="bookmark" title="February 20, 2010">Getting the Page and EPiServer CurrentPage object from HttpContext</a></li>
<li><a href="http://www.frederikvig.com/2010/05/creating-a-contact-form-with-asp-net-mvc/" rel="bookmark" title="May 13, 2010">Creating a contact form with ASP.NET MVC</a></li>
</ul>
<p><!-- Similar Posts took 14.618 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EPiServer filter – part 2: create your own filter</title>
		<link>http://www.frederikvig.com/2009/06/episerver-filter-part-2/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=episerver-filter-part-2</link>
		<comments>http://www.frederikvig.com/2009/06/episerver-filter-part-2/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 16:35:19 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=79</guid>
		<description><![CDATA[If you haven&#8217;t, be sure to check out EPiServer filter &#8211; part 1. In one of my project I had a bunch of categories and needed to filter a PageDataCollection to find pages that had one or more of the categories. Out of the box EPiServer has no filter class that does this, so I [...]]]></description>
			<content:encoded><![CDATA[<p>If you haven&#8217;t, be sure to check out <a href="http://www.frederikvig.com/2009/05/episerver-filter-part-1/">EPiServer filter &#8211; part 1</a>.</p>
<p>In one of my project I had <a href="http://sdk.episerver.com/library/CMS6/html/T_EPiServer_Core_CategoryList.htm">a bunch of categories</a> and needed to filter a PageDataCollection to find pages that had one or more of the categories. Out of the box EPiServer has no filter class that does this, so I needed to create my own. This was actually pretty easy. I created a new class and implemented the <a href="http://sdk.episerver.com/library/cms6/html/T_EPiServer_Filters_IPageFilter.htm">EPiServer.Filters.IPageFilter</a> interface which has three method signatures.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span>EPiServer.<span style="color: #0000FF;">Core</span>.<span style="color: #0000FF;">PageDataCollection</span> pages<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EPiServer.<span style="color: #0000FF;">Filters</span>.<span style="color: #0000FF;">FilterEventArgs</span> e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> ShouldFilter<span style="color: #000000;">&#40;</span>EPiServer.<span style="color: #0000FF;">Core</span>.<span style="color: #0000FF;">PageData</span> page<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>I then added a public property of type CategoryList for my categories. Then in my filter method I traversed the PageDataCollection and looked for matches, if there was no match the page got removed.<br />
<h3>The complete code</h3>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FilterAtLeastOneCategory <span style="color: #008000;">:</span> IPageFilter
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> CategoryList Categories
	<span style="color: #000000;">&#123;</span>
	    get<span style="color: #008000;">;</span>
	    set<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> FilterAtLeastOneCategory<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> FilterAtLeastOneCategory<span style="color: #000000;">&#40;</span>CategoryList categoryList<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Categories</span> <span style="color: #008000;">=</span> categoryList<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i<span style="color: #008000;">--</span><span style="color: #000000;">&#41;</span>
	    <span style="color: #000000;">&#123;</span>
		<span style="color: #FF0000;">bool</span> isMatch <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
		var categoryList <span style="color: #008000;">=</span> pages<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">Category</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>categoryList <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var category <span style="color: #0600FF;">in</span> categoryList<span style="color: #000000;">&#41;</span>
		    <span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var currentCategory <span style="color: #0600FF;">in</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Categories</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
			    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>category <span style="color: #008000;">==</span> currentCategory<span style="color: #000000;">&#41;</span>
			    <span style="color: #000000;">&#123;</span>
				isMatch <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
			    <span style="color: #000000;">&#125;</span>
			<span style="color: #000000;">&#125;</span>
		    <span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>isMatch<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		    pages.<span style="color: #0000FF;">RemoveAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	    <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, FilterEventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Pages</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> ShouldFilter<span style="color: #000000;">&#40;</span>PageData page<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I could then use my new filter class.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var currentCategories <span style="color: #008000;">=</span> CurrentPage.<span style="color: #0000FF;">Category</span><span style="color: #008000;">;</span>
<span style="color: #008000;">new</span> FilterAtLeastOneCategory<span style="color: #000000;">&#40;</span>currentCategories<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>myPageDataCollection<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Filter by Role</h3>
<p>Here is another custom filter that removes all pages that the specified role doesn&#8217;t have access to.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Core</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">EPiServer.Filters</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Filters</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FilterRole <span style="color: #008000;">:</span> IPageFilter
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> RoleName
        <span style="color: #000000;">&#123;</span>
            get<span style="color: #008000;">;</span>
            set<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> roleName<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">RoleName</span> <span style="color: #008000;">=</span> roleName<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> i <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i<span style="color: #008000;">--</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">bool</span> isMatch <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
                var acl <span style="color: #008000;">=</span> pages<span style="color: #000000;">&#91;</span>i<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">ACL</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>acl <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>var role <span style="color: #0600FF;">in</span> acl<span style="color: #000000;">&#41;</span>
                    <span style="color: #000000;">&#123;</span>
                        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>role.<span style="color: #0000FF;">Key</span> <span style="color: #008000;">==</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">RoleName</span><span style="color: #000000;">&#41;</span>
                        <span style="color: #000000;">&#123;</span>
                            isMatch <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                        <span style="color: #000000;">&#125;</span>
                    <span style="color: #000000;">&#125;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">!</span>isMatch<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    pages.<span style="color: #0000FF;">RemoveAt</span><span style="color: #000000;">&#40;</span>i<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, FilterEventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Pages</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> ShouldFilter<span style="color: #000000;">&#40;</span>PageData page<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> FilterRole<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Everyone&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>pages<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/" rel="bookmark" title="November 27, 2009">Removing duplicates from a PageDataCollection</a></li>
<li><a href="http://www.frederikvig.com/2009/11/extending-episerver-categories/" rel="bookmark" title="November 27, 2009">Extending EPiServer Categories</a></li>
<li><a href="http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/" rel="bookmark" title="September 17, 2009">Extending search field with suggestion box</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-filter-part-1/" rel="bookmark" title="May 28, 2009">EPiServer filter &#8211; part 1</a></li>
<li><a href="http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/" rel="bookmark" title="June 16, 2009">EPiServer Extension Methods part 2</a></li>
</ul>
<p><!-- Similar Posts took 14.295 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/06/episerver-filter-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CSS tricks &#8211; part 1</title>
		<link>http://www.frederikvig.com/2009/05/css-tricks-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=css-tricks-part-1</link>
		<comments>http://www.frederikvig.com/2009/05/css-tricks-part-1/#comments</comments>
		<pubDate>Sun, 31 May 2009 14:52:55 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[Web design]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=49</guid>
		<description><![CDATA[Here are a few CSS tricks I&#8217;ve picked up along the way. Always visible vertical scrollbar When you have a fixed width centered web site open you&#8217;ve probably noticed that the page sometimes jumps a little. This is because the vertical scrollbar only is visible if the content is longer than the viewport, if no [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a few CSS tricks I&#8217;ve picked up along the way.</p>
<h3>Always visible vertical scrollbar</h3>
<p>When you have a fixed width centered web site open you&#8217;ve probably noticed that the page sometimes jumps a little. This is because the vertical scrollbar only is visible if the content is longer than the viewport, if no vertical scrollbar is visible in the browser. To always have the vertical scrollbar visible you can use the CSS hack below.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html <span style="color: #00AA00;">&#123;</span>
    overflow-y<span style="color: #00AA00;">:</span> <span style="color: #993333;">scroll</span><span style="color: #00AA00;">;</span>	
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h3>CSS reset styles</h3>
<p>To make our lives as web developers easier we have a few css reset style rules which will help make things more consistent across browsers. It started out with simply setting the padding and margin of all elements to 0 with this CSS code.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">margin</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">padding</span><span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Though this caused a few problems with form elements. After a few years of using the technique above I started using a CSS reset stylesheet.</p>
<ul>
<li><a href="http://meyerweb.com/eric/tools/css/reset/">Eric Meyer&#8217;s CSS Reset</a></li>
<li><a href="http://developer.yahoo.com/yui/reset/">YUI Reset CSS</a></li>
</ul>
<h3>100% min-height</h3>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">min-height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">background-color</span><span style="color: #00AA00;">:</span> <span style="color: #cc00cc;">#000</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Internet Explorer 6 has problems understanding the min-height property. Therefor I use the star selector hack to target IE6 and set the height property (IE6 uses the height property the same way as min-height, so if the content is bigger the page will still grow, like with min-height).</p>
<p><a href="http://reference.sitepoint.com/css/min-height">More information about the min-height property</a></p>
<h3>Star selector hack</h3>
<p>Applying * html {selector here} will only target Internet Explorer 5.5 and 6. Which makes this a nice way to still use valid CSS and only target those two browsers. Like in the min-height example above.</p>
<p>More information: <a href="http://reference.sitepoint.com/css/workaroundsfilters">Workarounds and Filters</a></p>
<h3>Internet Explorer 6 double margin bug</h3>
<p>When setting the float property to either left or right and having a margin set in the same direction as the float (either margin-left or margin-right) will give IE6 users twice the margin.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This will give IE6 users a left margin of 20px. Fortunately it is easy to fix. Simply add the display property and set it to inline.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>  
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">margin-left</span><span style="color: #00AA00;">:</span> <span style="color: #933;">10px</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">inline</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>This has no negative effect on other browsers. Also, when floating inline elements (a, span, em, etc), the element automatically becomes the same as when using display:block.</p>
<h4>More on floats</h4>
<ul>
<li><a href="http://css.maxdesign.com.au/floatutorial/">Step by Step CSS float tutorial</a></li>
<li><a href="http://reference.sitepoint.com/css/floatclear">Floating and clearing</a></li>
</ul>
<h3>hasLayout in Internet Explorer</h3>
<blockquote><p>“Layout” is an IE/Win proprietary concept that determines how elements draw and bound their content, interact with and relate to other elements, and react on and transmit application/user events.</p>
<p>This quality can be irreversibly triggered by some CSS properties. Some HTML elements have “layout” by default.</p>
<p>Microsoft developers decided that elements should be able to acquire a “property” (in an object-oriented programming sense) they referred to as hasLayout, which is set to true when this rendering concept takes effect.</p>
</blockquote>
<p>Source: <a href="http://www.satzansatz.de/cssd/onhavinglayout.html">satzansatz.de</a></p>
<p>I mostly come across this when I have no width or height applied. Like in the code below.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Overflow: hidden will clear the floats in all browsers except for in IE6. I could fix this by giving #wrapper a width or by floating it. But that is not always possible. Instead I can use the star selector and give IE6 a height of 1% to just trigger hasLayout.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">overflow</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">hidden</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #00AA00;">*</span> html <span style="color: #cc00cc;">#wrapper</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;"><span style="color: #cc66cc;">1</span>%</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#sidebar</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">200px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#content</span> <span style="color: #00AA00;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span><span style="color: #00AA00;">;</span>
    <span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">600px</span><span style="color: #00AA00;">;</span>
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<h4>More information on hasLayout<br />
<h4>
<ul>
<li><a href="http://www.satzansatz.de/cssd/onhavinglayout.html">satzansatz.de</a></li>
<li><a href="http://reference.sitepoint.com/css/haslayout">The Internet Explorer hasLayout Property</a></li>
</ul>
<h3>Displaying a pointer cursor for button, label and select elements</h3>
<p>I always add this code when I start a new project.</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">input<span style="color: #00AA00;">&#91;</span>type<span style="color: #00AA00;">=</span>submit<span style="color: #00AA00;">&#93;</span><span style="color: #00AA00;">,</span> button<span style="color: #00AA00;">,</span> label<span style="color: #00AA00;">,</span> select <span style="color: #00AA00;">&#123;</span> 
    <span style="color: #000000; font-weight: bold;">cursor</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">pointer</span><span style="color: #00AA00;">;</span> 
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Just to make it easier for users to see where they can click.</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/02/guide-to-font-sizing-with-css/" rel="bookmark" title="February 6, 2010">Guide to font sizing with CSS</a></li>
<li><a href="http://www.frederikvig.com/2009/11/flash-and-flash-video-episerver-dynamic-content/" rel="bookmark" title="November 17, 2009">Flash and Flash Video EPiServer Dynamic Content</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-5-creating-the-search-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 16, 2009">Part 5: Creating the search page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-4-creating-the-standard-page-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 13, 2009">Part 4: Creating the standard page – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2009/11/better-breadcrumb-trail/" rel="bookmark" title="November 14, 2009">Better breadcrumb trail</a></li>
</ul>
<p><!-- Similar Posts took 15.588 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/css-tricks-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>EPiServer filter &#8211; part 1</title>
		<link>http://www.frederikvig.com/2009/05/episerver-filter-part-1/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=episerver-filter-part-1</link>
		<comments>http://www.frederikvig.com/2009/05/episerver-filter-part-1/#comments</comments>
		<pubDate>Thu, 28 May 2009 20:31:52 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=41</guid>
		<description><![CDATA[Often we need to filter some of the pages in our PageDataCollection. Perhaps we wish to only show the pages that are published or that the user has access to. For this EPiServer has a few filter classes. Below you&#8217;ll find some examples. More information in the EPiServer SDK under the EPiServer.Filter namespace Lets start [...]]]></description>
			<content:encoded><![CDATA[<p>Often we need to filter some of the pages in our PageDataCollection. Perhaps we wish to only show the pages that are published or that the user has access to. For this EPiServer has a few filter classes. Below you&#8217;ll find some examples. More information in the <a href="http://sdk.episerver.com/library/cms6/html/N_EPiServer_Filters.htm">EPiServer SDK under the EPiServer.Filter namespace</a></p>
<p>Lets start by creating a PageDataCollection of the current pages children</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">PageDataCollection news <span style="color: #008000;">=</span> GetChildren<span style="color: #000000;">&#40;</span>CurrentPage.<span style="color: #0000FF;">PageLink</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Remember to add using EPiServer.Filters; to use the filter classes.</p>
<h3>Remove pages that are not published</h3>
<h4>EPiServer 4</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> FilterPublished<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <span style="color: #008000;">new</span> FilterEventArgs<span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h4>EPiServer CMS 5 &amp; 6</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> FilterPublished<span style="color: #000000;">&#40;</span>PagePublishedStatus.<span style="color: #0000FF;">Published</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>More information on the <a href="http://sdk.episerver.com/library/cms6/html/T_EPiServer_Core_PagePublishedStatus.htm">PagePublishedStatus enum in the SDK</a>.</p>
<h3>Filter by both published and read access</h3>
<h4>EPiServer CMS 5 &amp; 6</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">FilterForVisitor.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Filter by access level</h3>
<p>If the user does not at least have edit access, the page will get removed.</p>
<h4>EpiServer CMS 5 &amp; 6</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// using EPiServer.Security;</span>
<span style="color: #008000;">new</span> FilterAccess<span style="color: #000000;">&#40;</span>AccessLevel.<span style="color: #0000FF;">Edit</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>More information on the <a href="http://sdk.episerver.com/library/cms6/html/T_EPiServer_Security_AccessLevel.htm">AccessLevel enum in the SDK</a>.</p>
<h3>Sort the collection after a property value</h3>
<h4>EPiServer CMS 5 &amp; 6</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Default is Ascending</span>
<span style="color: #008000;">new</span> FilterPropertySort<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;PageName&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">new</span> FilterPropertySort<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;PageName&quot;</span>, FilterSortDirection.<span style="color: #0000FF;">Descending</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Filter out pages where a property has no value</h3>
<h4>EPiServer CMS 5 &amp; 6<H4></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> FilterRemoveNullValues<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MainBody&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Filter by a custom property</h3>
<h4>EPiServer CMS 5 &amp; 6</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> FilterCompareTo<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;PageVisibleInMenu&quot;</span>, <span style="color: #666666;">&quot;true&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>news<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>In the EPiServer SDK there is a nice overview of the built in <a href="http://sdk.episerver.com/library/cms6/html/P_EPiServer_Core_PageData_Property.htm">EPiServer properties</a>.<br />
<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/" rel="bookmark" title="July 20, 2009">EPiServer web controls: PageList</a></li>
<li><a href="http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/" rel="bookmark" title="June 16, 2009">EPiServer Extension Methods part 2</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
<li><a href="http://www.frederikvig.com/2009/06/episerver-filter-part-2/" rel="bookmark" title="June 28, 2009">EPiServer filter – part 2: create your own filter</a></li>
<li><a href="http://www.frederikvig.com/2009/10/episerver-findpageswithcriteria-and-findallpageswithcriteria/" rel="bookmark" title="October 21, 2009">EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria</a></li>
</ul>
<p><!-- Similar Posts took 11.048 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/episerver-filter-part-1/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Master Pages and EPiServer CurrentPage property</title>
		<link>http://www.frederikvig.com/2009/05/master-pages-and-episerver-currentpage-property/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=master-pages-and-episerver-currentpage-property</link>
		<comments>http://www.frederikvig.com/2009/05/master-pages-and-episerver-currentpage-property/#comments</comments>
		<pubDate>Wed, 20 May 2009 20:50:08 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=33</guid>
		<description><![CDATA[When you use user controls or web forms in your EPiServer web application you usually inherit from either UserControlBase or TemplatePage. Which gives you, among other things, the CurrentPage property. The problem is when you need the CurrentPage property in your Master Page. The way I usually fix this is with this code. var page [...]]]></description>
			<content:encoded><![CDATA[<p>When you use user controls or web forms in your EPiServer web application you usually inherit from either UserControlBase or TemplatePage. Which gives you, among other things, the CurrentPage property. The problem is when you need the CurrentPage property in your Master Page.</p>
<p>The way I usually fix this is with this code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">var page <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>PageBase<span style="color: #000000;">&#41;</span> Page<span style="color: #008000;">;</span>
...
<span style="color: #0000FF;">page</span>.<span style="color: #0000FF;">CurrentPage</span>.<span style="color: #0000FF;">PageName</span><span style="color: #008000;">;</span>
page.<span style="color: #0000FF;">CurrentPage</span>.<span style="color: #0000FF;">LinkURL</span><span style="color: #008000;">;</span>
...</pre></div></div>

<p>This should work fine in both EPiServer 4 and 5.</p>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2010/01/a-developers-guide-to-pagetypebuilder/" rel="bookmark" title="January 15, 2010">A developer&#8217;s guide to PageTypeBuilder</a></li>
<li><a href="http://www.frederikvig.com/2010/02/getting-the-page-and-episerver-currentpage-object-from-httpcontext/" rel="bookmark" title="February 20, 2010">Getting the Page and EPiServer CurrentPage object from HttpContext</a></li>
<li><a href="http://www.frederikvig.com/2009/10/sending-confirmation-email-to-the-user-when-using-episerver-xforms/" rel="bookmark" title="October 17, 2009">Sending confirmation email to the user when using EPiServer XForms</a></li>
<li><a href="http://www.frederikvig.com/2009/11/the-selectedtemplate-and-duplicate-code/" rel="bookmark" title="November 11, 2009">The SelectedTemplate and duplicate code</a></li>
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
</ul>
<p><!-- Similar Posts took 14.575 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/master-pages-and-episerver-currentpage-property/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EPiServer Link Collection Property</title>
		<link>http://www.frederikvig.com/2009/05/episerver-link-collection/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=episerver-link-collection</link>
		<comments>http://www.frederikvig.com/2009/05/episerver-link-collection/#comments</comments>
		<pubDate>Mon, 18 May 2009 18:59:38 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=31</guid>
		<description><![CDATA[The EPiServer Link Collection Property allows you to add links to web pages, documents and e-mail addresses. For a nice overview see this post: EPiServer 5 R2 and Link Collection property In this example I&#8217;m going to show you how to use the link collection property to get a page reference to EPiServer pages and [...]]]></description>
			<content:encoded><![CDATA[<p>The EPiServer Link Collection Property allows you to add links to web pages, documents and e-mail addresses. For a nice overview see this post: <a href="http://marekblotny.blogspot.com/2009/02/episerver-5-r2-and-link-collection.html">EPiServer 5 R2 and Link Collection property</a>
</p>
<p>In this example I&#8217;m going to show you how to use the link collection property to get a page reference to EPiServer pages and retrieve some content from them. This could be used for a related content sidebar or something similar.</p>
<p>Start by creating a new link collection property in admin mode to an existing page type or a new one, name it RelatedContent. Then go to edit mode and add a few links to various pages.</p>
<p>Now we&#8217;ll start on the page template, open up your web form and add this markup.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Repeater runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptRelatedContent&quot;</span> OnItemDataBound<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptRelatedContent_ItemDataBound&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>ul id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;relatedContent&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>li<span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>h3<span style="color: #008000;">&gt;&lt;</span>asp<span style="color: #008000;">:</span>HyperLink runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;lnkHeading&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>h3<span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>asp<span style="color: #008000;">:</span>Literal runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ltlText&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>li<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>FooterTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>ul<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>FooterTemplate<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Repeater<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Then in your code-behind.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>IsValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;RelatedContent&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// using EPiServer.SpecializedProperties;</span>
	var relatedContent <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>LinkItemCollection<span style="color: #000000;">&#41;</span>CurrentPage<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;RelatedContent&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>relatedContent <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    rptRelatedContent.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> relatedContent<span style="color: #008000;">;</span>
	    rptRelatedContent.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> rptRelatedContent_ItemDataBound<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, RepeaterItemEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">ItemType</span> <span style="color: #008000;">==</span> ListItemType.<span style="color: #0000FF;">Item</span> <span style="color: #008000;">||</span> e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">ItemType</span> <span style="color: #008000;">==</span> ListItemType.<span style="color: #0000FF;">AlternatingItem</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	var linkItem <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>LinkItem<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">DataItem</span><span style="color: #008000;">;</span>
	var lnkHeading <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HyperLink<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lnkHeading&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	var ltlText <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Literal<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ltlText&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>linkItem <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> lnkHeading <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> ltlText <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    var url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlBuilder<span style="color: #000000;">&#40;</span>linkItem.<span style="color: #0000FF;">Href</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// using EPiServer.Web;</span>
	    <span style="color: #FF0000;">bool</span> isEPiServerPage <span style="color: #008000;">=</span> PermanentLinkMapStore.<span style="color: #0000FF;">ToMapped</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>isEPiServerPage<span style="color: #000000;">&#41;</span>
	    <span style="color: #000000;">&#123;</span>
		var page <span style="color: #008000;">=</span> DataFactory.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">GetPage</span><span style="color: #000000;">&#40;</span>PermanentLinkUtility.<span style="color: #0000FF;">GetPageReference</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		    lnkHeading.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Heading&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> <span style="color: #FF0000;">string</span> <span style="color: #008000;">??</span> page.<span style="color: #0000FF;">PageName</span><span style="color: #008000;">;</span>
		    lnkHeading.<span style="color: #0000FF;">NavigateUrl</span> <span style="color: #008000;">=</span> page.<span style="color: #0000FF;">LinkURL</span><span style="color: #008000;">;</span>
&nbsp;
		    ltlText.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> GetText<span style="color: #000000;">&#40;</span>page, <span style="color: #FF0000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	    <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The GetText method I usually place in a static helper class. It is just to get 255 characters of text from the pages MainIntro property or if it is empty from the MainBody property:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetText<span style="color: #000000;">&#40;</span>PageData page, <span style="color: #FF0000;">int</span> textLength<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    var text <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MainIntro&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> string<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>text<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	text <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MainBody&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> string<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>text<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// using EPiServer.Core.Html;</span>
    <span style="color: #0600FF;">return</span> TextIndexer.<span style="color: #0000FF;">StripHtml</span><span style="color: #000000;">&#40;</span>text, textLength<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You could also add it as an extension method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Simply add the this keyword in front of PageData</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetText<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> PageData page, <span style="color: #FF0000;">int</span> textLength<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
...
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then you can call it like this instead:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ltlText.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> page.<span style="color: #0000FF;">GetText</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/" rel="bookmark" title="June 16, 2009">EPiServer Extension Methods part 2</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-extension-methods/" rel="bookmark" title="May 4, 2009">EPiServer Extension Methods</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-property/" rel="bookmark" title="July 5, 2009">EPiServer web controls: Property</a></li>
</ul>
<p><!-- Similar Posts took 20.431 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/episerver-link-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->