<?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>nerdboy.co.uk &#187; asp.net</title>
	<atom:link href="http://www.nerdboy.co.uk/category/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.nerdboy.co.uk</link>
	<description>nerdboy blog - web development stuff</description>
	<lastBuildDate>Mon, 06 Feb 2012 14:31:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Observations on moving code from VB.NET to C#</title>
		<link>http://www.nerdboy.co.uk/2011/03/observations-on-moving-code-from-vb-net-to-csharp/</link>
		<comments>http://www.nerdboy.co.uk/2011/03/observations-on-moving-code-from-vb-net-to-csharp/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 10:32:46 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[csharp]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=178</guid>
		<description><![CDATA[I&#8217;ve been programming in VB.NET since the dotnet framework was launched, but never really felt the need to try C#. I&#8217;ve just decided to try it&#8230; Since both VB.NET and C# use the same framework I was expecting that switching between the 2 should be easy. We&#8217;ll it&#8217;s not quite as plain sailing as I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been programming in VB.NET since the dotnet framework was launched, but never really felt the need to try C#.  I&#8217;ve just decided to try it&#8230;<br />
Since both VB.NET and C# use the same framework I was expecting that switching between the 2 should be easy.  We&#8217;ll it&#8217;s not quite as plain sailing as I expected.</p>
<p>I&#8217;m moving an existing project over piece-by-piece.  As I come across stumbling blocks I&#8217;m adding them to this post.</p>
<p><span id="more-178"></span></p>
<h3>Code formatting</h3>
<p>There isn&#8217;t the automatic formatting of code that you get with VB.NET in Visual Studio</p>
<h3>Correct us of ToString</h3>
<p><strong>Error: Cannot convert method group &#8216;ToString&#8217; to non-delegate type &#8216;string&#8217;. Did you intend to invoke the method?</strong><br />
When using the following code:</p>
<pre class="brush: vb; title: ; notranslate">
Regex.Replace(Regex.Replace(aString, aRegexPattern, &quot;-&quot;), &quot;-{2,}&quot;, &quot;-&quot;).ToString;
</pre>
<p>Cause:<br />
.ToString without brackets is a property, I needed to call </p>
<pre class="brush: vb; title: ; notranslate">
.ToString()
</pre>
<h3>No optional parameters on methods</h3>
<p>You have to overload the method instead</p>
<h3>Passing char into a method</h3>
<p><strong>Error: The best overloaded method match for &#8216;string.PadLeft(int, char)&#8217; has some invalid arguments</strong></p>
<p>Using:</p>
<pre class="brush: vb; title: ; notranslate">
aDate.Day.ToString().PadLeft(2, &quot;0&quot;)
</pre>
<p>For some reason the char in the PadLeft needs to be wrapped in single quotes not double.</p>
<p>Fix:</p>
<pre class="brush: vb; title: ; notranslate">
aDate.Day.ToString().PadLeft(2, '0')
</pre>
<h3>Parameters need to be exact</h3>
<p><strong>It&#8217;s a lot more picky about the types you pass into methods</strong><br />
In VB.NET I was getting away with passing a Double into Rectangle initialiser that actually wanted an int.</p>
<pre class="brush: vb; title: ; notranslate">
double outputHeight = 0;
double outputWidth = 0;

Rectangle rec = new Rectangle(0, 0, outputWidth, outputHeight);
</pre>
<p>Gives the error: The best overloaded method match for &#8216;System.Drawing.Rectangle.Rectangle(int, int, int, int)&#8217; has some invalid arguments</p>
<p>Fixed with:</p>
<pre class="brush: vb; title: ; notranslate">
Rectangle rec = new Rectangle(0, 0, (int)outputWidth, (int)outputHeight);
</pre>
<h3>Dividing 2 integers</h3>
<p>Dividing 2 integers in VB.NET returns a Double.<br />
But in C# the following returns zero:</p>
<pre class="brush: vb; title: ; notranslate">
int imageHeight = 768;
int imageWidth = 1024;
outputHeight =  imageHeight / imageWidth;
</pre>
<p>This works:</p>
<pre class="brush: vb; title: ; notranslate">
outputHeight =  (Double) imageHeight / (Double) imageWidth;
</pre>
<h3>Saving a Bitmap</h3>
<p>I was ensuring the Bitmap was saved with 100% quality like:</p>
<pre class="brush: vb; title: ; notranslate">
System.Drawing.Imaging.EncoderParameter qualityParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality,100);
</pre>
<p>I was getting an error &#8220;Parameter is not valid&#8221;.  Finally traced it to the 100 parameter C# wanted it explicitly typed, using 100L</p>
<pre class="brush: vb; title: ; notranslate">
System.Drawing.Imaging.EncoderParameter qualityParam = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Quality,
&lt;strong&gt;100L&lt;/strong&gt;);
</pre>
<h3>Container.DataItem</h3>
<pre class="brush: vb; title: ; notranslate">
&lt;%#Container.DataItem[&quot;value&quot;]%&gt;
</pre>
<p>Gives the error: Cannot apply indexing with [] to an expression of type &#8216;object&#8217;</p>
<p>Fixed by changing to:</p>
<pre class="brush: vb; title: ; notranslate">
&lt;# DataBinder.Eval(Container.DataItem, &quot;value&quot;) %&gt;
</pre>
<h3>
Case sensitivity!<br />
</h3>
<p>Not working:</p>
<pre class="brush: vb; title: ; notranslate">
&lt;%# container.findcontrol(&quot;filePhoto&quot;).clientid()%&gt;
</pre>
<p>Working (Notice capital C, I and D in ClientID):</p>
<pre class="brush: vb; title: ; notranslate">
&lt;%# Container.FindControl(&quot;filePhoto&quot;).ClientID%&gt;
</pre>
<h3>Request.QueryString</h3>
<p>You need to change Request.QueryString(&#8220;carid&#8221;) to Request.QueryString["carid"]</p>
<h3>Accessing a field in a DataRow</h3>
<p>Using</p>
<pre class="brush: vb; title: ; notranslate">
hypSubSection.Text = drCar(&quot;car&quot;);
</pre>
<p>Gives the following error &#8220;&#8216;drCar&#8217; is a &#8216;variable&#8217; but is used like a &#8216;method&#8217;&#8221;</p>
<p>It needs to be:</p>
<pre class="brush: vb; title: ; notranslate">
hypSubSection.Text = drCar[&quot;car&quot;].ToString();
</pre>
<h3>Raising events</h3>
<p>Nice and easy in VB.NET<br />
Declare the event:</p>
<pre class="brush: vb; title: ; notranslate">
Public Event cropped(ByVal aString As string)
</pre>
<p>Raise the event</p>
<pre class="brush: vb; title: ; notranslate">
RaiseEvent cropped(&quot;something&quot;)
</pre>
<p>In C# you need </p>
<pre class="brush: vb; title: ; notranslate">
    //declaring the event handler delegate
    public delegate void CropEventHandler(string aString);
    //declaring the event
    public event CropEventHandler cropped;
</pre>
<p>Then raise it with</p>
<pre class="brush: vb; title: ; notranslate">
     if (cropped != null)
        {
            cropped(paramsToPassBack);
        }
</pre>
<p>Debugging this cropped was always null.  This turned out to be because nothing was listening to the event!<br />
This doesn&#8217;t seem right to me, as the point of using a delegate is go make the object raising the event independent to any objects listening for the event.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2011/03/observations-on-moving-code-from-vb-net-to-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop validation controls scrolling to top of the page</title>
		<link>http://www.nerdboy.co.uk/2010/12/stop-validation-controls-scrolling-to-top-of-the-page/</link>
		<comments>http://www.nerdboy.co.uk/2010/12/stop-validation-controls-scrolling-to-top-of-the-page/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 11:46:28 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=159</guid>
		<description><![CDATA[This has been bugging me for ages. When a validation control fires the page scrolls to the top. Very annoying when your form is further down the page. A very easy way to stop this happening is to override the window.scroll function. Add the following to the page with the form on.]]></description>
			<content:encoded><![CDATA[<p>This has been bugging me for ages.  When a validation control fires the page scrolls to the top.  Very annoying when your form is further down the page.</p>
<p>A very easy way to stop this happening is to override the window.scroll function.<br />
Add the following to the page with the form on.</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;
     window.scrollTo = function( x,y ) {
        return true;
    }
&lt;/script&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2010/12/stop-validation-controls-scrolling-to-top-of-the-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>maxlength for a multiline textbox</title>
		<link>http://www.nerdboy.co.uk/2010/03/maxlength-for-a-multiline-textbox/</link>
		<comments>http://www.nerdboy.co.uk/2010/03/maxlength-for-a-multiline-textbox/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 16:41:31 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=140</guid>
		<description><![CDATA[In asp.net you can set the attribute maxlength which works fine if the textmode is SingleLine, but if you set the textmode to MultiLine then maxlength no longer works. This is because the html that is rendered is a textarea instead on a regular input field. Customvalidator to the rescue! For example: This &#8220;fires&#8221; this [...]]]></description>
			<content:encoded><![CDATA[<p>In asp.net you can set the attribute maxlength which works fine if the textmode is SingleLine, but if you set the textmode to MultiLine then maxlength no longer works.</p>
<p>This is because the html that is rendered is a textarea instead on a regular input field.</p>
<p>Customvalidator to the rescue!</p>
<p>For example:</p>
<pre class="brush: xml; title: ; notranslate">
 &lt;asp:TextBox runat=&quot;server&quot; ID=&quot;txtIntro&quot; TextMode=&quot;MultiLine&quot; Rows=&quot;3&quot; /&gt;
 &lt;asp:CustomValidator runat=&quot;server&quot; ID=&quot;cvIntro&quot; maxlength=&quot;255&quot;
	ErrorMessage=&quot;Please enter 255 characters or less&quot;
	ControlToValidate=&quot;txtIntro&quot;
	ClientValidationFunction=&quot;checkTextAreaLength&quot; /&gt;
</pre>
<p></p>
<p>
This &#8220;fires&#8221; this clientside function:
</p>
<pre class="brush: jscript; title: ; notranslate">
&lt;script type=&quot;text/javascript&quot;&gt;
    function checkTextAreaLength(source, arguments) {
        var maxlength = $(source).attr(&quot;maxlength&quot;);
        if (maxlength == undefined) maxlength = 255;
        if (arguments.Value.length &gt; maxlength)
            arguments.IsValid = false;
        else
            arguments.IsValid = true;
    }

&lt;/script&gt;
</pre>
<p></p>
<p>One thing to note is that I&#8217;ve had to add the maxlength attribute to the customvalidator <strong>not </strong>to the textbox.  I would prefer to have maxlength set on the textbox but so far I&#8217;ve been unable to work this out.  If anyone has any ideas please let me know.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2010/03/maxlength-for-a-multiline-textbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting a labels &quot;for&quot; attribute inside a repeater</title>
		<link>http://www.nerdboy.co.uk/2009/11/setting-a-labels-for-attribute-inside-a-repeater/</link>
		<comments>http://www.nerdboy.co.uk/2009/11/setting-a-labels-for-attribute-inside-a-repeater/#comments</comments>
		<pubDate>Sun, 15 Nov 2009 20:08:48 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=138</guid>
		<description><![CDATA[It&#8217;s nice to add &#60;labels&#62; to your form fields and set the labels &#8220;for&#8221; attribute so that it references the field it is a label for. e.g. Now if you&#8217;re referencing asp.net controls you can use the clientid property. e.g. All nice an easy so far. The situation gets a little bit more complicated when [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s nice to add &lt;labels&gt; to your form fields and set the labels &#8220;for&#8221; attribute so that it references the field it is a label for.</p>
<p>e.g.</p>
<pre class="brush: xml; title: ; notranslate">&lt;label for=&quot;emailaddress&quot;&gt;Email&lt;/label&gt;
&lt;input type=&quot;text&quot; id=&quot;emailaddress&quot;/&gt;</pre>
<p>Now if you&#8217;re referencing asp.net controls you can use the clientid property.</p>
<p>e.g.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;label for=&quot;&lt;%= emailaddress.clientid()%&gt;&quot;&gt;Email&lt;/label&gt;
&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;emailaddress&quot; /&gt;
</pre>
<p>All nice an easy so far.  The situation gets a little bit more complicated when you start nesting this inside a repeater.</p>
<p>e.g.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Repeater runat=&quot;server&quot; ID=&quot;rpt1&quot;&gt;
&lt;itemTemplate&gt;

&lt;label for=&quot;&lt;%= emailaddress.clientid()%&gt;&quot;&gt;Email&lt;/label&gt;
&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;emailaddress&quot; /&gt;

&lt;/itemTemplate&gt;
&lt;/asp:Repeater&gt;
</pre>
<p>this won&#8217;t work.<br />
Here&#8217;s what you need to do instead.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;asp:Repeater runat=&quot;server&quot; ID=&quot;rpt1&quot;&gt;
&lt;itemTemplate&gt;

&lt;label for=&quot;&lt;%# container.findcontrol(&quot;emailaddress&quot;).clientid()%&gt;&quot;&gt;Email&lt;/label&gt;
&lt;asp:TextBox runat=&quot;server&quot; ID=&quot;emailaddress&quot; /&gt;

&lt;/itemTemplate&gt;
&lt;/asp:Repeater&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/11/setting-a-labels-for-attribute-inside-a-repeater/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jQuery and asp.net validation controls</title>
		<link>http://www.nerdboy.co.uk/2009/04/jquery-and-aspnet-validation-controls/</link>
		<comments>http://www.nerdboy.co.uk/2009/04/jquery-and-aspnet-validation-controls/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 06:08:51 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=101</guid>
		<description><![CDATA[Just found a  nice tip to check with jQuery if all built-in asp.net validation controls on a form are valid. As an asp.net developer and jQuery advocate I know I&#8217;m going to find this tip very useful http://devoma.com/post/JQuery-and-ASPNET-validators.aspx]]></description>
			<content:encoded><![CDATA[<p>Just found a  nice tip to check with jQuery if all built-in asp.net validation controls on a form are valid.</p>
<p>As an asp.net developer and jQuery advocate I know I&#8217;m going to find this tip very useful</p>
<p><a href="http://devoma.com/post/JQuery-and-ASPNET-validators.aspx">http://devoma.com/post/JQuery-and-ASPNET-validators.aspx</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/04/jquery-and-aspnet-validation-controls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>asp.net viewstate and seo</title>
		<link>http://www.nerdboy.co.uk/2009/03/aspnet-viewstate-and-seo/</link>
		<comments>http://www.nerdboy.co.uk/2009/03/aspnet-viewstate-and-seo/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 10:18:50 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[seo]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=80</guid>
		<description><![CDATA[asp.net viewstate is a wonderful invention, but can bloat your html.  For most users this is probably going to have minimal impact on the page load time.  But for search engines spiders you really want to minimise needless information, especially near the top of the page. It&#8217;s best practice to turn off viewstate for the [...]]]></description>
			<content:encoded><![CDATA[<p>asp.net viewstate is a wonderful invention, but can bloat your html.  For most users this is probably going to have minimal impact on the page load time.  But for search engines spiders you really want to minimise needless information, especially near the top of the page.</p>
<p>It&#8217;s best practice to turn off viewstate for the whole page or for individual usercontrols if they don&#8217;t require viewstate.  The deciding factor here is: does the page or usercontrol perform postbacks.</p>
<p>Even with careful pruning of viewstate you&#8217;ll probably find your viewstate is still large&#8230;</p>
<p><strong>What you can do</strong></p>
<p>Now there are a couple of strategies I&#8217;ve seen for working round this, both involve overriding the page</p>
<p>1 is to intercept the page rendering and move the viewstate hidden variable to the bottom of the page.</p>
<p>Here&#8217;s an example <a href="http://www.dotnetdiary.com/labels/Moving%20ViewState%20Field.html">http://www.dotnetdiary.com/labels/Moving%20ViewState%20Field.html</a></p>
<p>2 is a very clever solution that keeps the viewstate information on the server and justs passes a key back and forth to the client.</p>
<p>I read about this approach here <a href="http://www.eggheadcafe.com/articles/20040613.asp">http://www.eggheadcafe.com/articles/20040613.asp</a></p>
<p><strong>Here&#8217;s my approach</strong></p>
<p>Now since I don&#8217;t think that viewstate bloat has too much of an impact on page performance for real users I&#8217;m only going to worry about search engine spiders.</p>
<p>asp.net has a way of detecting spiders &#8211; now I&#8217;m not saying it&#8217;s going to be 100% accurate but in my tests it&#8217;s been accurate enough for this technique.</p>
<p>In the page load of your page (or master page)</p>
<pre class="brush: vb; title: ; notranslate">If Request.Browser.Crawler Then Page.EnableViewState = False</pre>
<p>er that&#8217;s it, pretty simply eh? <img src='http://www.nerdboy.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>You can verify if this is working by viewing the source of the cached version of the page that google holds.</p>
<p>Hope that helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/03/aspnet-viewstate-and-seo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.NET Event Validation and “Invalid Callback Or Postback Argument”</title>
		<link>http://www.nerdboy.co.uk/2009/02/aspnet-event-validation-and-%e2%80%9cinvalid-callback-or-postback-argument%e2%80%9d/</link>
		<comments>http://www.nerdboy.co.uk/2009/02/aspnet-event-validation-and-%e2%80%9cinvalid-callback-or-postback-argument%e2%80%9d/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 21:15:05 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=59</guid>
		<description><![CDATA[I was getting this and pulling my hair out. My button (server-side) was pumping out a bit of javascript  And this kept causing the error. I tried using the prescribed fix: ClientScript.RegisterForEventValidation(mycontrol.uniqueid) in the prerender.  Still got the error. Here&#8217;s how I fixed it.  RegisterStartupScript does the job of running at startup by emiting the js right [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting this and pulling my hair out.</p>
<p>My button (server-side) was pumping out a bit of javascript </p>
<pre class="brush: vb; title: ; notranslate">Page.ClientScript.RegisterStartupScript(GetType(String),
         &quot;loginunsuccessful&quot;, &quot;&lt;script type=&quot;&quot;text/javascript&quot;&quot;&gt;
         alert('Login unsuccessful – please try again');&lt;/script&gt;&quot;)</pre>
<p>And this kept causing the error.</p>
<p>I tried using the prescribed fix: ClientScript.RegisterForEventValidation(mycontrol.uniqueid) in the prerender.  Still got the error.</p>
<p><strong>Here&#8217;s how I fixed it.</strong>  RegisterStartupScript does the job of running at startup by emiting the js right at the foot of the page.  I wrapped my JS in jQuery&#8217;s own onload code.</p>
<pre class="brush: vb; title: ; notranslate">Page.ClientScript. RegisterStartupScript(GetType(String),
          &quot;loginunsuccessful&quot;, &quot;&lt;script type=&quot;&quot;text/javascript&quot;&quot;&gt;
          $(document).ready(function(){alert('Login unsuccessful – please try again');});
          &lt;/script&gt;&quot;)</pre>
<p>Still the same error, I then changed to using Page.ClientScript.RegisterClientScriptBlock, which emits the JS in the midst of the html and hey presto no errors.  This is without using the RegisterForEventValidation I&#8217;d like to add.</p>
<p>Final code:</p>
<pre class="brush: vb; title: ; notranslate">Page.ClientScript.RegisterClientScriptBlock(GetType(String),
          &quot;loginunsuccessful&quot;, &quot;&lt;script type=&quot;&quot;text/javascript&quot;&quot;&gt;
          $(document).ready(function(){BlockAlert('Login unsuccessful – please try again');});
          &lt;/script&gt;&quot;)</pre>
<p>Simple to fix when you know how.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/02/aspnet-event-validation-and-%e2%80%9cinvalid-callback-or-postback-argument%e2%80%9d/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Need to access session variables in an ashx?</title>
		<link>http://www.nerdboy.co.uk/2009/01/need-to-access-session-variables-in-an-ashx/</link>
		<comments>http://www.nerdboy.co.uk/2009/01/need-to-access-session-variables-in-an-ashx/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 16:58:50 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[ashx]]></category>
		<category><![CDATA[session]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=48</guid>
		<description><![CDATA[Just a quick note if you need to access session variables from an ashx, you need to implement SessionState.IRequiresSessionState or IReadOnlySessionState if you only need to read the vars In your ashx change to]]></description>
			<content:encoded><![CDATA[<p>Just a quick note if you need to access session variables from an ashx, you need to implement SessionState.IRequiresSessionState or IReadOnlySessionState if you only need to read the vars</p>
<p>In your ashx change</p>
<pre class="brush: vb; title: ; notranslate">Public Class yourclass :     Implements IHttpHandler

    Implements SessionState.IRequiresSessionStat</pre>
<p>to</p>
<pre class="brush: vb; title: ; notranslate">Public Class yourclass

Implements IHttpHandler

    Implements SessionState.IRequiresSessionStat</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2009/01/need-to-access-session-variables-in-an-ashx/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Required field validator for an fckeditor</title>
		<link>http://www.nerdboy.co.uk/2008/10/required-field-validator-for-an-fckeditor/</link>
		<comments>http://www.nerdboy.co.uk/2008/10/required-field-validator-for-an-fckeditor/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 14:39:09 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>
		<category><![CDATA[fckeditor]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=28</guid>
		<description><![CDATA[Unfortunately a requiredfieldvalidator doesn&#8217;t work with the fckeditor. The way to do this is to use a custom validator. Important note: you need to set validateemptytext=&#8221;true&#8221; otherwise it doesn&#8217;t fire Then add the following javascript (note that I&#8217;m using jQuery here to reference the validator control) You might also want to handle the server-side validation [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately a requiredfieldvalidator doesn&#8217;t work with the fckeditor.</p>
<p>The way to do this is to use a custom validator.</p>
<pre class="brush: xml; title: ; notranslate"> </pre>
<p>Important note: you need to set validateemptytext=&#8221;true&#8221; otherwise it doesn&#8217;t fire</p>
<p>Then add the following javascript (note that I&#8217;m using jQuery here to reference the validator control)</p>
<pre class="brush: jscript; title: ; notranslate">&lt;script type=&quot;text/javascript&quot;&gt;// &lt;![CDATA[
function ValidateContentText(source,args)
{
var controltovalidate = jQuery(source).attr(&quot;controltovalidate&quot;);
var fckControl = FCKeditorAPI.GetInstance(controltovalidate);
args.IsValid = fckControl.GetXHTML(true) != &quot;&quot;;
}
// ]]&gt;&lt;/script&gt;</pre>
<p>You might also want to handle the server-side validation too, even though if client-side isn&#8217;t working then the fckeditor won&#8217;t be working&#8230;</p>
<pre class="brush: vb; title: ; notranslate">Protected Sub cvIntro_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles cvIntro.ServerValidate

Dim myContentPlaceHolder As ContentPlaceHolder

myContentPlaceHolder = CType(Master.FindControl(&quot;cphMain&quot;), ContentPlaceHolder)

Dim fckEditorToCheck As FredCK.FCKeditorV2.FCKeditor

fckEditorToCheck = myContentPlaceHolder.FindControl(CType(source, CustomValidator).ControlToValidate)

args.IsValid = Not String.IsNullOrEmpty(fckEditorToCheck.Value)

End Sub</pre>
</pre>
<p><strong>Update 2011</strong></p>
<pre class="brush: jscript; title: ; notranslate">
var controltovalidate = jQuery(source).attr(&quot;controltovalidate&quot;);
</pre>
</pre>
<p>No longer works... just use</p>
<pre class="brush: jscript; title: ; notranslate">
var controltovalidate = source.controltovalidate;
</pre>
</pre>
<p>Instead - easy peasy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2008/10/required-field-validator-for-an-fckeditor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Find a control within a  area</title>
		<link>http://www.nerdboy.co.uk/2008/10/find-a-control-within-a-area/</link>
		<comments>http://www.nerdboy.co.uk/2008/10/find-a-control-within-a-area/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 13:52:05 +0000</pubDate>
		<dc:creator>nerdboy</dc:creator>
				<category><![CDATA[asp.net]]></category>

		<guid isPermaLink="false">http://www.nerdboy.co.uk/?p=21</guid>
		<description><![CDATA[If you are using master pages, you may expect that you can find a control within an tag with the following me.findcontrol("fckEditor") But unfortunately that doesn&#8217;t work. You need to make a reference to the place holder the control is in, then find the control within the place holder. Another gotcha here is that you [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using master pages, you may expect that you can find a control within an  tag with the following</p>
<pre lang="vbnet">me.findcontrol("fckEditor")</pre>
<p>But unfortunately that doesn&#8217;t work.<br />
You need to make a reference to the place holder the control is in, then find the control within the place holder.<br />
Another gotcha here is that you need to find this control based on the id it has on the master page not the id it has in the page in question.<br />
e.g.<br />
If the tags on the page are</p>
<pre lang="html">&lt;asp:Content ID="Content2" ContentPlaceHolderID="cphMain" Runat="Server"&gt;
&lt;/asp:Content&gt;</pre>
<p>You need to create a reference to the place holder with</p>
<pre lang="vbnet">Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("cphMain"), ContentPlaceHolder)</pre>
<p>and not</p>
<pre lang="vbnet">Dim myContentPlaceHolder As ContentPlaceHolder
myContentPlaceHolder = CType(Master.FindControl("Content2"), ContentPlaceHolder)</pre>
<p>Hope that saves someone some time!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.nerdboy.co.uk/2008/10/find-a-control-within-a-area/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

