<?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>Codelab Blog &#187; Visual Basic</title>
	<atom:link href="http://blog.codelab.co.nz/category/visual-basic/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +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>Using UserControl.RenderControl()</title>
		<link>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/</link>
		<comments>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/#comments</comments>
		<pubDate>Mon, 06 Jun 2011 22:08:15 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=341</guid>
		<description><![CDATA[Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose? Firstly, here is the code to render the html from a user control to a string builder object: &#160; &#160;Dim sb As New StringBuilder() &#160; &#160;Using sw As New StringWriter(sb) &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps you want to reuse a usercontrol in a email? or you need to generate the html from a usercontrol for a specific purpose?</p>
<p>Firstly, here is the code to render the html from a user control to a string builder object:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;Dim sb As New StringBuilder()<br />
&nbsp; &nbsp;Using sw As New StringWriter(sb)<br />
&nbsp; &nbsp; &nbsp; Using htmlTw As New HtmlTextWriter(sw)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Dim ucUserControl As UCUserControl = LoadControl(&quot;myUserControl.ascx&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Visible = True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .Display() 'This is a custom method to do some processing<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ucUserControl .RenderControl(htmlTw)<br />
&nbsp; &nbsp; &nbsp; End Using<br />
&nbsp; &nbsp;End Using</div></div>
<p>Secondly, make sure that you set <em><strong>enableEventValidation=&#8221;false&#8221;</strong></em> on the page you are generating the html from.   You will get an error if this is enabled.   You could extend this futher by adding a boolean variable to the page and only disabling Event Validation while rending the control.</p>
<p>Thirdly, override the <em><strong>VerifyRenderingInServerForm</strong></em> method and make it doing &#8220;nothing&#8221;.   If you do not do this, you will get an error saying that you have no form sever tag in your user control.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Public Overrides Sub VerifyRenderingInServerForm(control As System.Web.UI.Control)<br />
'Do nothing<br />
End Sub</div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2011/06/07/using-usercontrol-rendercontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Detect when a session has ended ASP.NET</title>
		<link>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/</link>
		<comments>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 03:32:02 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[VB.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=259</guid>
		<description><![CDATA[A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session.   One solution is to add the following code into the Page_Init event.   You can add this event into a class that inherits the Page class so [...]]]></description>
			<content:encoded><![CDATA[<p>A problem that I have had in the past is trying to find out when a session has expired within ASP.NET and how to deal with the expired session.   One solution is to add the following code into the Page_Init event.   You can add this event into a class that inherits the Page class so that you can reuse on more than one page or all pages if needed.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">If Not Context.Session Is Nothing Then<br />
If Session.IsNewSession Then<br />
Dim szCookieHeader As String = Request.Headers(&quot;Cookie&quot;)<br />
If Not String.IsNullOrEmpty(szCookieHeader) And szCookieHeader.IndexOf(&quot;ASP.NET_SessionId&quot;) &amp;gt;= 0 Then<br />
Response.Redirect(&quot;/sessiontimeoutpage.aspx&quot;)<br />
End If<br />
End If<br />
End If</div></div>
<p>This code checks if a new session has been created and if the header has a ASP.NET Session id.   This makes sure that we are checking for a session that has just been created.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/06/30/detect-when-session-ended/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Match Whole Words Regular Expressions</title>
		<link>http://blog.codelab.co.nz/2010/01/12/match-whole-words-regular-expressions/</link>
		<comments>http://blog.codelab.co.nz/2010/01/12/match-whole-words-regular-expressions/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 00:00:10 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<category><![CDATA[.NET]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=168</guid>
		<description><![CDATA[Example: Dim regExp As New Regex(String.Format(&#8220;\b{0}\b&#8221;, keyword), RegexOptions.IgnoreCase) This is the same as doing the following: note.note_content.StartsWith(InputKeyword &#38;amp; &#34; &#34;) OR _ note.note_content.EndsWith(&#34; &#34; &#38;amp; InputKeyword) OR _ note.note_content.Contains(&#34; &#34; &#38;amp; InputKeyword &#38;amp; &#34; &#34;) References: http://answers.oreilly.com/topic/217-how-to-match-whole-words-with-a-regular-expression/ http://stackoverflow.com/questions/810078/search-for-whole-word-with-linq-to-sql]]></description>
			<content:encoded><![CDATA[<p>Example:</p>
<p>Dim regExp As New Regex(String.Format(&#8220;\b{0}\b&#8221;, keyword), RegexOptions.IgnoreCase)</p>
<p>This is the same as doing the following:</p>
<pre>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">note.note_content.StartsWith(InputKeyword &amp;amp; &quot; &quot;) OR _<br />
note.note_content.EndsWith(&quot; &quot; &amp;amp; InputKeyword) OR _<br />
note.note_content.Contains(&quot; &quot; &amp;amp; InputKeyword &amp;amp; &quot; &quot;)</div></div>
</pre>
<p><em><strong>References:</strong></em></p>
<p><a href="http://answers.oreilly.com/topic/217-how-to-match-whole-words-with-a-regular-expression/">http://answers.oreilly.com/topic/217-how-to-match-whole-words-with-a-regular-expression/</a></p>
<p><a href="http://stackoverflow.com/questions/810078/search-for-whole-word-with-linq-to-sql">http://stackoverflow.com/questions/810078/search-for-whole-word-with-linq-to-sql</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2010/01/12/match-whole-words-regular-expressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unable to cast object of type &#8216; Issue</title>
		<link>http://blog.codelab.co.nz/2009/12/22/unable-to-cast-object-of-type-issue/</link>
		<comments>http://blog.codelab.co.nz/2009/12/22/unable-to-cast-object-of-type-issue/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 01:04:27 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[Visual Basic]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=162</guid>
		<description><![CDATA[I came across this error: System.InvalidCastException: Unable to cast object of type &#8216;&#60;TakeIterator&#62;d__3a`1[Class]&#8216; to type &#8216;System.Collections.Generic.List`1[Class]&#8216;. This occured when trying to use the Take extension (list.Take(n)) from a generic list of objects.   The problem is when you use the Take extension, it returns a new sequence ( IEnumerable). I got around this issue by using: [...]]]></description>
			<content:encoded><![CDATA[<p>I came across this error:</p>
<p><span style="font-family: Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;">System.InvalidCastException: Unable to cast object of type &#8216;&lt;TakeIterator&gt;d__3a`1[Class]&#8216; to type &#8216;System.Collections.Generic.List`1[Class]&#8216;.</span></p>
<p><span style="font-family: Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;">This occured when trying to use the Take extension (list.Take(n)) from a generic list of objects.   The problem is when you use the Take extension, it returns a new sequence (</span></p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">IEnumerable).</div></div>
<p>I got around this issue by using:</p>
<p>list.Take(8).ToList() which gets the new sequence and then converts back to the generic list.</p>
<p><strong><em>References:</em></strong></p>
<p><a href="http://stackoverflow.com/questions/1431782/unable-to-cast-object">http://stackoverflow.com/questions/1431782/unable-to-cast-object</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/12/22/unable-to-cast-object-of-type-issue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

