<?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>phdesign</title>
	<atom:link href="http://www.phdesign.com.au/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phdesign.com.au</link>
	<description>phdesign web and application development by Paul Heasley</description>
	<lastBuildDate>Thu, 08 Jul 2010 00:08:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>WPF RadioButton Binding to IsChecked Property</title>
		<link>http://www.phdesign.com.au/programming/wpf-radiobutton-binding-to-ischecked-property/</link>
		<comments>http://www.phdesign.com.au/programming/wpf-radiobutton-binding-to-ischecked-property/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 00:08:30 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[wpf]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=226</guid>
		<description><![CDATA[I wasted a few development hours discovering this strange behaviour when binding to the IsChecked property of a RadioButton in WPF when using MVVM. You can read about the issue on the MSDN forum, but from my experience if you have a two way binding on the is IsChecked property of a RadioButton which is part [...]]]></description>
			<content:encoded><![CDATA[<p>I wasted a few development hours discovering this strange behaviour when binding to the IsChecked property of a RadioButton in WPF when using MVVM. You can <a title="RadioButton unchecked bindings issue still not resolved?" href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8eb8280a-19c4-4502-8260-f74633a9e2f2/">read about the issue on the MSDN forum</a>, but from my experience if you have a two way binding on the is IsChecked property of a RadioButton which is part of a group, then after you set the bound property in code a couple of times, the RadioButton loses it&#8217;s binding all together.<span id="more-226"></span></p>
<p>Here is my original code that kept losing it&#8217;s binding:</p>
<pre><code>&lt;ItemsControl ItemsSource="{Binding Elements}" Margin="0,10,0,10"&gt;
  &lt;ItemsControl.ItemTemplate&gt;
    &lt;DataTemplate&gt;
      &lt;RadioButton Content="{Binding Key}"
        GroupName="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Title}"
        IsChecked="{Binding Path=IsSelected}"
        Margin="0,5,0,5"/&gt;
    &lt;/DataTemplate&gt;
  &lt;/ItemsControl.ItemTemplate&gt;
&lt;/ItemsControl&gt;</code></pre>
<p>There a couple of ways to solve this,</p>
<ol>
<li><a title="Binding IsChecked property of RadioButton in WPF" href="http://pstaev.blogspot.com/2008/10/binding-ischecked-property-of.html">You can subclass the RadioButton</a></li>
<li><a title="Binding IsChecked property of RadioButton in WPF" href="http://pstaev.blogspot.com/2008/10/binding-ischecked-property-of.html"></a>You could use OneWay binding on IsChecked to set the RadioButton state from code, then bind the Command property to a  Command when user clicks on the RadioButton.
<pre><code>&lt;ItemsControl ItemsSource="{Binding Elements}" Margin="0,10,0,10"&gt;
  &lt;ItemsControl.ItemTemplate&gt;
    &lt;DataTemplate&gt;
      &lt;RadioButton Content="{Binding Key}"
        GroupName="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.Title}"
        IsChecked="{Binding Path=IsSelected, Mode=OneWay}"
        Command="{Binding IsSelectedCommand}"
        CommandParameter="{Binding}"
        Margin="0,5,0,5"/&gt;
    &lt;/DataTemplate&gt;
  &lt;/ItemsControl.ItemTemplate&gt;
&lt;/ItemsControl&gt;</code></pre>
</li>
<li>My preferred option: (<a title="RadioButton unchecked bindings issue still not resolved?" href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/8eb8280a-19c4-4502-8260-f74633a9e2f2/">as suggested by karliwatson</a>) use a ListBox for the grouping and bind the ListBoxItem&#8217;s IsSelected property to your ViewModel, then bind the RadioButton&#8217;s IsChecked property to the list box item&#8217;s IsSelected property. Don&#8217;t set a group on the RadioButton.
<pre><code>&lt;ListBox ItemsSource="{Binding Elements}" Margin="0,10,0,10" BorderThickness="0" Background="Transparent"&gt;
  &lt;ListBox.ItemContainerStyle&gt;
    &lt;Style TargetType="{x:Type ListBoxItem}"&gt;
      &lt;Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" /&gt;
      &lt;Setter Property="Template"&gt;
        &lt;Setter.Value&gt;
          &lt;ControlTemplate TargetType="ListBoxItem"&gt;
            &lt;ContentPresenter/&gt;
          &lt;/ControlTemplate&gt;
        &lt;/Setter.Value&gt;
      &lt;/Setter&gt;
    &lt;/Style&gt;
  &lt;/ListBox.ItemContainerStyle&gt;
  &lt;ListBox.ItemTemplate&gt;
    &lt;DataTemplate&gt;
        &lt;RadioButton Content="{Binding Key}"
            IsChecked="{Binding Path=IsSelected, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}}"
            Margin="0,5,0,5"/&gt;
    &lt;/DataTemplate&gt;
  &lt;/ListBox.ItemTemplate&gt;
&lt;/ListBox&gt;</code></pre>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/wpf-radiobutton-binding-to-ischecked-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Logging Messages in Dot Net</title>
		<link>http://www.phdesign.com.au/programming/logging-messages-in-dot-net/</link>
		<comments>http://www.phdesign.com.au/programming/logging-messages-in-dot-net/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 10:39:15 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=215</guid>
		<description><![CDATA[The .Net Framework provides an easy way to log messages using the System.Diagnostics.Trace class. By using Trace the user can configure where and what to log in the config file. Below are two simple ways to log a message to a text file. 1. The simplest way if you don&#8217;t care about the format of [...]]]></description>
			<content:encoded><![CDATA[<p>The .Net Framework provides an easy way to log messages using the System.Diagnostics.Trace class. By using Trace the user can configure where and what to log in the config file.</p>
<p>Below are two simple ways to log a message to a text file.<span id="more-215"></span></p>
<p>1. The simplest way if you don&#8217;t care about the format of the message is to use a filter on the trace listener in app.config to determine which events to log.</p>
<pre><code>&lt;system.diagnostics&gt;
  &lt;trace autoflush="true"&gt;
    &lt;listeners&gt;
      &lt;add name="LogListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log" traceOutputOptions="DateTime"&gt;
        &lt;!--
        EventTypes:
        Critical: Fatal error or application crash.
        Error: Recoverable error.
        Warning: Noncritical problem.
        Information: Informational message.
        Verbose: Debugging trace.
        Start: Starting of a logical operation.
        Stop: Stopping of a logical operation.
        Suspend: Suspension of a logical operation.
        Resume: Resumption of a logical operation.
        Transfer: Changing of correlation identity.
        --&gt;
        &lt;filter type="System.Diagnostics.EventTypeFilter" initializeData="Error"/&gt;
      &lt;/add&gt;
    &lt;/listeners&gt;
  &lt;/trace&gt;
&lt;/system.diagnostics&gt;</code></pre>
<p>Then you only need to call one of the following methods to log a message with a specific EventType.</p>
<pre><code>System.Diagnostics.Trace.TraceInformation("Information messge");
System.Diagnostics.Trace.TraceError("Error messge");</code></pre>
<p>2. If you want more control over the format of the message you can use a TraceSwitch in app.config:</p>
<pre><code>&lt;system.diagnostics&gt;
  &lt;switches&gt;
    &lt;clear/&gt;
    &lt;!--
    Trace Levels:
    Off: 0: None
    Error: 1: Only error messages
    Warning: 2: Warning messages and error messages
    Info: 3: Informational messages, warning messages, and error messages
    Verbose: 4: Verbose messages, informational messages, warning messages, and error messages
    --&gt;
    &lt;add name="LogLevel" value="Info"/&gt;
  &lt;/switches&gt;
  &lt;trace autoflush="true"&gt;
    &lt;listeners&gt;
      &lt;add name="LogListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="trace.log"/&gt;
    &lt;/listeners&gt;
  &lt;/trace&gt;
&lt;/system.diagnostics&gt;</code></pre>
<p>Then retrieve the TraceSwitch in code as follows:</p>
<pre><code>TraceSwitch logLevel = new TraceSwitch("LogLevel", "The logging level");
Trace.WriteLineIf(logLevel.Level &gt;= level, string.Format("[{0}] [{1}]: {2}", DateTime.Now, level, message));</code></pre>
<p>The examples are for a desktop application, but they would work equally well in a web application by configuring web.config. Note that web applications aren&#8217;t compiled with Trace enabled, so you need to enable them in web.config by using the following after the &lt;system.diagnostics&gt; node:</p>
<pre><code>&lt;system.codedom&gt;
  &lt;compilers&gt;
    &lt;compiler language="c#;cs;csharp"
      extension=".cs"
      compilerOptions="/d:TRACE"
      type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="1" /&gt;
    &lt;/compilers&gt;
&lt;/system.codedom&gt;</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/logging-messages-in-dot-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phreplace Goes Open Source</title>
		<link>http://www.phdesign.com.au/general/phreplace-goes-open-source/</link>
		<comments>http://www.phdesign.com.au/general/phreplace-goes-open-source/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 08:09:48 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[phreplace]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=193</guid>
		<description><![CDATA[I&#8217;ve decided to release phreplace as open source software in order to continue it&#8217;s development, I no longer have the time to give it the attention it deserves. The VB6 source code will be released under the GNU Lesser General Public License (LGPL), in my understanding this means that anyone can use phreplace and even [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve decided to release phreplace as open source software in order to continue it&#8217;s development, I no longer have the time to give it the attention it deserves.</p>
<p>The VB6 source code will be released under the GNU Lesser General Public License (LGPL), in my understanding this means that anyone can use phreplace and even include the library in a greater works (e.g. PSPad), however if they modify the code it must be released under a similar open source library, in order that everyone will benefit from the changes.</p>
<p>The source code is available at <a title="phreplace source code available at Assembla" href="https://www.assembla.com/spaces/phreplace/documents">Assembla</a>, feel free to send any code changes to me to be included in the project.<span id="more-193"></span></p>
<h3>Architecture</h3>
<p>I rewrote phreplace in early 2009 when I was studying design patterns and as such the VB6 source code is heavily object-oriented and pattern focused. VB6 is not strictly an oo language but it does support inheritance through the &#8216;Implements&#8217; keyword.</p>
<p>phreplace uses the iterator, observer and factory methods. I found some of the sample chapters of <em>Visual Basic design patterns: VB 6.0 and VB.NET</em> By James William Cooper on <a title="Visual Basic design patterns: VB 6.0 and VB.NET By James William Cooper" href="http://books.google.com.au/books?id=TLhvRJTKDssC&amp;lpg=PP1&amp;pg=PP1#v=onepage&amp;q&amp;f=false">Google Books</a> a very useful resource.</p>
<p>This early <a href="http://www.phdesign.com.au/wp-content/uploads/2010/06/phreplace-architecture.pdf">class architecture diagram (PDF)</a> may help decipher some of the code design.</p>
<h3>Future Direction</h3>
<p>phreplace was designed to be application agnostic, it currently works only with PSPad but I hoped that by implementing only a few interfaces (IHostAdapter, IDocument and IDocumentCollection) it could work with any other editor that supported the basic operations required. My next intended editor to support was SciTE.</p>
<p>The first major change that I would like to see is support for Vista / Windows 7. At present the phreplace.vbs script intialises the application by checking to see if the phreplace.dll library is registered, if it isn&#8217;t it tries to register it with regsvr32. This works for Windows XP but standard users aren&#8217;t able to register libraries in Vista / Windows 7. So far I have come up with 3 solutions.</p>
<ol>
<li>Override DllRegisterServer using <a title="Classic VB Tools: vbAdvance" href="http://vb.mvps.org/tools/vbAdvance/">vbAdvance</a>. I can&#8217;t get this library to work. See <a href="http://www.phdesign.com.au/programming/registering-phreplace-dll-in-windows-vista/" title="Registering phreplace DLL in Windows Vista">Registering phreplace DLL in Windows Vista</a>.</li>
<li>Create a separate utility similar to regsvr32 and include this with phreplace. I think this is messy. Again see <a href="http://www.phdesign.com.au/programming/registering-phreplace-dll-in-windows-vista/" title="Registering phreplace DLL in Windows Vista">Registering phreplace DLL in Windows Vista</a>.</li>
<li>Use the <a title="Registration-Free COM" href="http://msdn.microsoft.com/en-us/library/ms973913.aspx">Registration-Free COM</a> solution of adding a manifest file for PSPad which references the phreplace.dll library so that we don&#8217;t have to register it in the registry at all. This solution works for XP, see the <a title="reg-free-com branch of phreplace source code." href="https://www.assembla.com/code/phreplace/subversion/nodes/branches/reg-free-com?rev=5">reg-free-com branch of the source code</a>, but doesn&#8217;t seem to work for Vista. My theory is that perhaps Vista handles vbscript differently, so it doesn&#8217;t inherit the PSPad manifest. If someone could get this working I think this is the most elegant solution.</li>
</ol>
<p>I look forward to seeing user contributions to this project.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/general/phreplace-goes-open-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IE Autocomplete Doesn&#8217;t Fire onchange Event Handler</title>
		<link>http://www.phdesign.com.au/programming/ie-autocomplete-doesnt-fire-onchange-event-handler/</link>
		<comments>http://www.phdesign.com.au/programming/ie-autocomplete-doesnt-fire-onchange-event-handler/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 00:10:24 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=177</guid>
		<description><![CDATA[While testing an ASP validation control in Internet Explorer I found that the validation wasn&#8217;t triggered if I selected an item from the autocomplete list for a text box, this was the same in Safari for Windows, but worked fine in Mozilla Firefox. What?! Turns out that when selecting an item from the autocomplete list [...]]]></description>
			<content:encoded><![CDATA[<p>While testing an ASP validation control in Internet Explorer I found that the validation wasn&#8217;t triggered if I selected an item from the autocomplete list for a text box, this was the same in Safari for Windows, but worked fine in Mozilla Firefox. What?!</p>
<p><a href="http://www.phdesign.com.au/wp-content/uploads/2010/04/autocomplete.png"><img class="alignnone size-full wp-image-185" title="IE form autocomplete feature" src="http://www.phdesign.com.au/wp-content/uploads/2010/04/autocomplete.png" alt="IE form autocomplete feature" width="152" height="66" /></a></p>
<p><span id="more-177"></span>Turns out that when selecting an item from the autocomplete list the onchange event handler doesn&#8217;t fire, therefore the validation scripts don&#8217;t fire. The onblur event does fire however, meaning we can do a check to see if the data has changed and if so, manually fire the onchange event handler.</p>
<pre><code>/*
Author:     Paul Heasley
Date:       15.04.2010
Version:    0.1
Description:
IE and safari do not trigger the onchange events for textboxes when using autocomplete,
so validation events don't trigger. The blur event does trigger however so this script
checks to see if the value has changed (by saving the value on focus) and manually
calling onchange.
*/
function onChangeFix() {
    var previousValue = [];
    // Get all input elements
    var inputs = document.getElementsByTagName('input');

    for (var i = 0; i &lt; inputs.length; i++) {
        var elt = inputs[i];

        // Only update text boxes. Depending on your application you
        // may also need to fix text areas.
        if (elt.type.toLowerCase() == "text")
        {
            // Save old value.
            addEvent(elt, 'focus', function() {
                previousValue[this] = this.value;
            });

            // Compare to old value, do we need to trigger an onchange event?
            addEvent(elt, 'blur', function() {
                if (previousValue[this] != this.value)
                {
                    if (this.onchange)
                        this.onchange();
                }
            });

            // Set old value = new value to stop the blur event triggering
            // another onchange.
            addEvent(elt, 'change', function() {
                previousValue[this] = this.value;
            });
        }
    }
}</code></pre>
<p>Alternatively, you can disable the autocomplete feature by adding the attrribute autocomplete=&#8221;off&#8221; for either a specific input or for the entire form.</p>
<pre><code>&lt;form id="theForm" name="theForm" method="post" autocomplete="off"&gt;</code></pre>
<p>Download the entire code sample including the addEvent() function.</p>
<p><a title="Download the source" href="http://www.phdesign.com.au/wp-content/uploads/2010/04/autocomplete_fix.js"><img class="alignnone size-full wp-image-126" src="http://www.phdesign.com.au/wp-content/uploads/2009/11/button_download_source.gif" alt="Download the source" width="149" height="25" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/ie-autocomplete-doesnt-fire-onchange-event-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Registering phreplace DLL in Windows Vista</title>
		<link>http://www.phdesign.com.au/programming/registering-phreplace-dll-in-windows-vista/</link>
		<comments>http://www.phdesign.com.au/programming/registering-phreplace-dll-in-windows-vista/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 10:10:46 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[dll]]></category>
		<category><![CDATA[phreplace]]></category>
		<category><![CDATA[vb6]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=165</guid>
		<description><![CDATA[is a VB6 DLL which is called from a vbscript plugin for PSPad. The script tests to see if the correct version of the DLL is registered on this computer, if not it registers it using regsvr32. This works fine in XP but not Vista where the script will error. A while ago a user [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.phdesign.com.au/phreplace/" title="phreplace Multiline search / replace for PSPad">phreplace</a> is a VB6 DLL which is called from a vbscript plugin for <a title="PSPad editor for developers" href="http://www.pspad.com/">PSPad</a>. The script tests to see if the correct version of the DLL is registered on this computer, if not it registers it using regsvr32. This works fine in XP but not Vista where the script will error.</p>
<p>A while ago a user pointed out to me <a title="Self Registering DLL's" href="http://www.experts-exchange.com/Programming/System/Windows__Programming/Q_21243930.html">this article on Experts Exchange</a> explaining why administrative rights are required to register a DLL in Windows Vista, in the hopes that we could automate the registration of phreplace in Vista.<span id="more-165"></span></p>
<p>Feeling defeated, I decided to explain why I haven&#8217;t been able to do this yet.</p>
<p>The fundamental problem is that Vista requires administrative privledges to write to the registry key required to register DLLs:</p>
<p>HKEY_CLASSES_ROOT\</p>
<p>However the user can register DLLs in their own section of the registry:</p>
<p>HKEY_CURRENT_USER\SOFTWARE\Classes\</p>
<p>So all is well right? Well not if you&#8217;re using VB6, you see when you run regsvr32, it calls the methods DllRegisterSever and DllUnregisterSever  to add / remove entries from the registry, these methods are generated automatically by VB6 to register to HKEY_CLASSES_ROOT, and there is no way to change this.</p>
<p>Well, there is one way. Apparently the <a title="vbAdvance Visual Basic addon" href="http://vb.mvps.org/tools/vbAdvance/">vbAdvance</a> addon for VB6 allowed a user to customise DllRegisterServer / DllUnregisterServer, this sounds great, except that it doesn&#8217;t work. I tried modifying these methods according to the instruction, but the resulting DLL just wont register. I even tried registering the included example DLL in the download package, but this threw the same error.</p>
<p>I&#8217;m certain it must have worked at some stage, they wouldn&#8217;t have included an example that didn&#8217;t work, so I can&#8217;t figure out what&#8217;s different. Did it only work in Windows 98 or 2000?</p>
<p>So in summary, for as long as I&#8217;m using VB6 I don&#8217;t think I can change where phreplace tries to register the DLL, the only other workaround is to use RegOverridePredefKey to tell the registry to redirect any calls to HKEY_CLASSES_ROOT to HKEY_CURRENT_USER\SOFTWARE\Classes, this would work but I don&#8217;t think it can be done with vbscript, so I would need to add another executable to phreplace to use in registering / unregistering the DLL from the registry, seems pretty messy.</p>
<p>If you&#8217;ve got any tips for me (especially how I can customise DllRegisterServer) feel free to email me. I haven&#8217;t setup the facility for leaving comments on this site yet, sorry.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/registering-phreplace-dll-in-windows-vista/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>No Validation Messages when Disabling &amp; Enabling ASP.Net Validator in Javascript</title>
		<link>http://www.phdesign.com.au/programming/no-validation-messages-when-disabling-enabling-asp-net-validator-in-javascript/</link>
		<comments>http://www.phdesign.com.au/programming/no-validation-messages-when-disabling-enabling-asp-net-validator-in-javascript/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 06:21:31 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[asp]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[howto]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=152</guid>
		<description><![CDATA[Need to validate a form field based on the value of another field in ASP.Net? The .Net Framework provides a javascript function to do just that: ValidatorEnable(val, enable) This function takes the validator control (val) and a boolean to determine whether it should be enable or disabled. The problem with this function is that it [...]]]></description>
			<content:encoded><![CDATA[<p>Need to validate a form field based on the value of another field in ASP.Net? The .Net Framework provides a javascript function to do just that:</p>
<pre><code>ValidatorEnable(val, enable)</code></pre>
<p>This function takes the validator control (val) and a boolean to determine whether it should be enable or disabled. The problem with this function is that it triggers the validator to validate itself immediately, showing any validation error messages before the user has submitted the form, which may not always be want you want.  The alternative is to set the validator&#8217;s enabled property to trigger this validator to validate itself when the user submits the form, and by using the Page_IsValid variable you can test whether the user has triggered a validation or not, then use ValidatorEnable function only after the validation has occurred when the user expects to see validation messages.<span id="more-152"></span></p>
<p>Consider a scenario where you want the user to enter their address only if they select Australia as the country, you also need to validate the address fields. Two ways to approach this are:</p>
<ol>
<li>For each address field you need to validate use a CustomValidator control, and in the ClientValidationFunction first check to see if the country is set to Australia and if it&#8217;s not then consider any response for this control as valid. The problem with this is you will have to recrete all of the validator functionality in your client validation function, which means more work.</li>
<li>Use standard validator controls for the address fields, and enable or disable them in javascript.  The code you call to enable or disable the validators could be a CustomValidation control on the country field, or a standard javascript call when the user selects a country. If the Page_IsValid variable is set to true then assume that the page has just been loaded and no validation has occured, in this case just set the validator controls enabled property so it will be validated (or not) when the user submits the form.<br />
If Page_IsValid is false then assume the user has tried to submit but failed, in this case we expect validation messages to show / hide as the user changes data on the form &#8211; this is the normal ASP.Net behaviour.</li>
</ol>
<p>Here&#8217;s an example:</p>
<pre><code>// The ClientValidationFunction of a custom validator for country
function validateCountry(source, args) {
    // We we haven't submitted the form yet
    if (Page_IsValid) {
        // Turn the postcode validator on / off, but don't validate
        requiredFieldValidatorPostcode.enabled = enable;
    } else {
        // Turn the postcode validator on / off, and immediately validate
        ValidatorEnable(requiredFieldValidatorPostcode, enable);
    }

    // Validate country is not empty
    args.IsValid = (args.Value.length &gt; 0);
}</code></pre>
<p>Don&#8217;t forget to include server side code to mimic this enabling / disabling of validators. To do this override the Validate() function, enable or disable validators depending on the country selected and call the base.Validate() function.</p>
<pre><code>public override void Validate()
{
    // Check if we need to validate the postcode.
    bool requireAddress = (dropDownListCountry.Text == "Australia");
    requiredFieldValidatorPostcode.Enabled = requireAddress;

    // Call the normal validation methods.
    base.Validate();
}

protected void customValidatorCountry_ServerValidate(object source, ServerValidateEventArgs args)
{
    // Implement the server side custom validation for country.
    args.IsValid = (args.Value.Length &gt; 0);
}</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/no-validation-messages-when-disabling-enabling-asp-net-validator-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting Topfield PVR Recordings</title>
		<link>http://www.phdesign.com.au/general/converting-topfield-pvr-recordings/</link>
		<comments>http://www.phdesign.com.au/general/converting-topfield-pvr-recordings/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 06:21:33 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[ipod]]></category>
		<category><![CDATA[topfield]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=148</guid>
		<description><![CDATA[This weekend I&#8217;ve been having fun moving some recording off the full hard drive of my Topfield Masterpiece and trying to convert them into the formats I want. Below is what I&#8217;ve learnt in the process, this is only going to be useful to those using Windows. Moving data off the PVR If you want [...]]]></description>
			<content:encoded><![CDATA[<p>This weekend I&#8217;ve been having fun moving some recording off the full hard drive of my Topfield Masterpiece and trying to convert them into the formats I want. Below is what I&#8217;ve learnt in the process, this is only going to be useful to those using Windows.<span id="more-148"></span></p>
<h2>Moving data off the PVR</h2>
<p>If you want to use your recordings on devices other than your Toppy, you&#8217;re going to need to get the recordings off it. Fortunately this is the simplest step. For me there were really two options:</p>
<ol>
<li>Use the provided USB link from the Toppy and the official <a title="Topfield tools, Altair USB transfer software." href="http://www.itopfield.com.au/download-utilities.asp?idx=15&amp;tb=">ALTAIR software</a> to download the recordings. For one or two recording this will be fine, although for me it took around 4 hours for a normal sized movie.</li>
<li>Attach the hard drive to your computer use <a title="TopfHD Read-Write to copy data from a Topfield hard drive" href="http://www.tapworld.net/content/view/75/47/">TopfHD Read-Write</a> to copy the recordings over to your PC hard drive.<br />
WARNING! To do this you will need to open your Topfield up to remove the hard drive, in doing so you will void your warrenty. I wouldn&#8217;t recommend doing this unless your Toppy is out of warrenty anyway.<br />
You need to use the TopfHD application to transfer files because Windows won&#8217;t recognise the file format of the Toppy hard drive. Be very careful not let Windows modify the disk in any way.<br />
Transferring about 8 recorded shows and 4 movies took under 30 mins, this takes longer to set up but is well worth it if you&#8217;re trying to move a bit of data.</li>
</ol>
<h2>Watching / Converting the Recordings</h2>
<p>Once you&#8217;ve got the recordings on your PC they will be in Topfield&#8217;s .rec format, which Windows Media nor Quicktime can recognise. My traditional way of converting these files for buring to a DVD went;</p>
<ol>
<li>Use <a title="Project X - DVB demux Tool" href="http://sourceforge.net/projects/project-x/">ProjectX</a> to convert to m2v file</li>
<li>Use TMPGEnc DVD Author to convert to DVD format</li>
<li>Use Nero to burn to DVD.</li>
</ol>
<p>If you just want to watch them on your computer I&#8217;ve got some great news which took me a while to realise: the .rec files can be played directly by the ever useful <a title="VLC Media Player" href="http://www.videolan.org/">VLC Media Player</a>.</p>
<p>If you want to convert them to another format, VLC can help you there too. Use the Media &gt; Convert / Save option to convert it into many different formats. Supposedly it can convert to H264 / mp4 format  compatible with iPods, however I had real problems with this, the video would be distorted or the audio would be way out of sync. So, after playing around for a while, I thought I give it a go converting directly form <a title="Handbrake iPod video conversion" href="http://handbrake.fr/">Handbrake</a> which I do most of my iPod video conversions with&#8230; and this works great!</p>
<p>In summary,</p>
<p><strong>To convert to DVD</strong>: Probably still use ProjectX &gt; TMPGEnc DVD Author &gt; DVD.</p>
<p><strong>To convert to iPod:</strong> Use Handbrake.</p>
<p><strong>To watch or convert to other media formats:</strong> Use VLC Media Player.</p>
<p>Hope this is useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/general/converting-topfield-pvr-recordings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Certified Professional Training Kit 70-536 Errata</title>
		<link>http://www.phdesign.com.au/programming/microsoft-certified-professional-training-kit-70-536-errata/</link>
		<comments>http://www.phdesign.com.au/programming/microsoft-certified-professional-training-kit-70-536-errata/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 22:37:19 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[training]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=145</guid>
		<description><![CDATA[I&#8217;m currently studying for the Microsoft® .NET Framework 2.0—Application Development Foundation (70-536) exam, using the Microsoft Press Training Kit and I am appalled at the number of errors, both editorial and technical, in this book. There are whole paragraphs that have been taken out of one chapter and used as a place holder in another [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently studying for the Microsoft® .NET Framework 2.0—Application Development Foundation (70-536) exam, using the Microsoft Press Training Kit and I am appalled at the number of errors, both editorial and technical, in this book. There are whole paragraphs that have been taken out of one chapter and used as a place holder in another chapter then never changed, at one stage I was very confused when the book was talking about two different classes that seemed to do the same thing, only to find that they were the same class, it&#8217;s name had just be written wrong in places, arrggg.<span id="more-145"></span></p>
<p>The problem I find is when I&#8217;m not sure about something in the book, I don&#8217;t know whether my understanding is wrong or the book is wrong, so I went hunting for a list of known errors and sure enough, Microsoft already know about them, in fact there are so many they created 4 knowledge base pages for them! When combining these in a Word document it ended up being 90+ pages, that&#8217;s really bad.</p>
<p>If you have this book or think about getting it, here are the official list of updates from Microsoft:</p>
<p><a title="70-536 Comments and Corrections Part 1" href="http://support.microsoft.com/kb/923018" target="_blank">MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation comments and corrections Part 1</a></p>
<p><a title="70-536 Comments and Corrections Part 2" href="http://support.microsoft.com/kb/935218/" target="_blank">MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 2</a></p>
<p><a title="70-536 Comments and Corrections Part 3" href="http://support.microsoft.com/kb/949730/" target="_blank">MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 3</a></p>
<p><a title="70-536 Comments and Corrections Part 4" href="http://support.microsoft.com/kb/949734/" target="_blank">MCTS Self-Paced Training Kit (Exam 70-536): Microsoft® .NET Framework 2.0—Application Development Foundation Comments and Corrections Part 4</a></p>
<p>Perhaps it&#8217;s time to reprint the book?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/programming/microsoft-certified-professional-training-kit-70-536-errata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phreplace version 2.0.24 released</title>
		<link>http://www.phdesign.com.au/general/phreplace-version-2-0-24-released/</link>
		<comments>http://www.phdesign.com.au/general/phreplace-version-2-0-24-released/#comments</comments>
		<pubDate>Sat, 19 Dec 2009 04:21:52 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[phreplace]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/?p=137</guid>
		<description><![CDATA[I&#8217;ve made a couple of updates to phreplace and created a new . The changes include: Handling an exception that occurs in the vbscript Regex object when using a badly formed regular expression (e.g. reader.(\w)+\(reader.GetOrdinal\(&#8220;(\w)+&#8221;)); &#8211; note I forgot to escape the last parenthesis). Added Write to Log option (which defaults to off) to write some debugging [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a couple of updates to phreplace and created a new <a href="http://www.phdesign.com.au/phreplace/" title="phreplace">version 2.0.24 which is available here</a>. The changes include:<span id="more-137"></span></p>
<ul>
<li>Handling an exception that occurs in the vbscript Regex object when using a badly formed regular expression (e.g. reader.(\w)+\(reader.GetOrdinal\(&#8220;(\w)+&#8221;)); &#8211; note I forgot to escape the last parenthesis).</li>
<li>Added Write to Log option (which defaults to off) to write some debugging log events to a &#8216;phreplace.log&#8217; file in the same folder as the &#8216;phreplace.dll&#8217; library. This should help identify the issue for a user where the latest version of phreplace just doesn&#8217;t open (no error &#8211; no nothing).</li>
<li>Not a change but rather a note: Tried to understand the vbscript Regex object&#8217;s handling of &#8216;.&#8217;. Apparently it matches a new line (\n) but not a carriage return (\r) which is why doing a replace all with ^(.+)$  was acting  strange, try this instead ^([^\r\n]+)$.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/general/phreplace-version-2-0-24-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phdesign website 2.2 live</title>
		<link>http://www.phdesign.com.au/general/phdesign-website-2-2-live/</link>
		<comments>http://www.phdesign.com.au/general/phdesign-website-2-2-live/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 06:25:04 +0000</pubDate>
		<dc:creator>paul</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[webdesign]]></category>

		<guid isPermaLink="false">http://www.phdesign.com.au/general/phdesign-website-2-2-live/</guid>
		<description><![CDATA[Finally the new version of phdesign.com.au is live. Based on wordpress this site will hopefully be more active than it has been in the past. There are still areas to complete such as the portfolio section, but that shouldn&#8217;t be too far away. Now that I won&#8217;t be spending as much time on this site&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Finally the new version of <a title="phdesign web design and development by paul heasley" href="http://www.phdesign.com.au">phdesign.com.au</a> is live. Based on <a title="Powered by WordPress, state-of-the-art semantic personal publishing platform." href="http://wordpress.org">wordpress</a> this site will hopefully be more active than it has been in the past. There are still areas to complete such as the portfolio section, but that shouldn&#8217;t be too far away. Now that I won&#8217;t be spending as much time on this site&#8217;s development perhaps I can focus more on <a href="http://www.phdesign.com.au/phreplace/" title="phreplace Mutliline search and replace add-on for PSPad">phreplace</a>, although I should spend some more time studying for my MCPD exams.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.phdesign.com.au/general/phdesign-website-2-2-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
