<?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>nPath Ltd. &#187; ASP.net</title>
	<atom:link href="http://www.npathweb.com/tag/aspnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.npathweb.com</link>
	<description>Web Development Blog</description>
	<lastBuildDate>Mon, 22 Feb 2010 15:16:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fun with site migration</title>
		<link>http://www.npathweb.com/2009/02/11/fun-with-site-migration/</link>
		<comments>http://www.npathweb.com/2009/02/11/fun-with-site-migration/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 19:25:11 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Visual Studio 2007]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/?p=58</guid>
		<description><![CDATA[
Here is my latest headache:
Server Error in &#8216;/&#8217; Application.


A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 &#8211; Error [...]]]></description>
			<content:encoded><![CDATA[<p><span><br />
Here is my latest headache:</span></p>
<h1>Server Error in &#8216;/&#8217; Application.</h1>
<h1>
<hr size="1" /></h1>
<h2><em>A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 &#8211; Error Locating Server/Instance Specified)</em></h2>
<p>I recently migrated my dedicated server from the worthless company AIT to the cloud computing division of RackSpace. As a result I had to move my SQL database. No Problem I thought. I&#8217;ll just edit my web.config and go about my merry business. Well that is when the above error appeared.  This peticular site is dynamically compiled VB site with code in the aspx pages. (no code behind).</p>
<p>The data access layer is handled by some dataset files with XSD extentions. I found that when the files were created the web config connections strings were coppied but not dynamically linked. Each table adpter&#8217;s connection sting needed pointed at the web config again. The process was slow due to the now-remote database.</p>
<p>Now that the table adapters have updated their connection strings all is well.<em><br />
</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/11/fun-with-site-migration/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Serializing and de-serializing a listbox to XML</title>
		<link>http://www.npathweb.com/2009/02/05/serializing-and-de-serializing-a-listbox-to-xml/</link>
		<comments>http://www.npathweb.com/2009/02/05/serializing-and-de-serializing-a-listbox-to-xml/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:07:42 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=26</guid>
		<description><![CDATA[In this post I will discuss how I stored a list of strings in a single database field as xml.
The application I&#8217;m working on has a list of email addresses for each contact. Rather than creating a new table with forgein keys, stored procedures, Data access componants, and business layer logic I decided to take a regular email field [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will discuss how I stored a list of strings in a single database field as xml.</p>
<p>The application I&#8217;m working on has a list of email addresses for each contact. Rather than creating a new table with forgein keys, stored procedures, Data access componants, and business layer logic I decided to take a regular email field and expand it to store a list of emails. My Datastore is SQL Server. I only changed the field to nvarchar(max).</p>
<p>To save the list</p>
<ol>
<li>edit the list as needed</li>
<li>pull the listbox.items collection and convert to an array</li>
<li>Serialize the array and store the text in the database</li>
</ol>
<p>To get it back</p>
<ol>
<li>read the text from the database</li>
<li>de-serialize to an array</li>
<li>load the array as items in the listbox</li>
</ol>
<p>The issue I had was that the xmlserializer works with streams. This I was not used to. I needed to convert from string to stream and backagain. Looking back it isn&#8217;t hard but for me it was a learning curve.</p>
<p>Here is the code then pulls the listbox and converts the items to an XML string:</p>
<pre><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;">

      </span></pre>
<pre><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">        <span style="color: #006400;">'create and populate an array, the items collection is not serializable</span>
         Dim</span> emails <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> ArrayList()</span></pre>
<p><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"> For</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Each</span> itm <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> ListItem <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">In</span> ListBox1.Items<br />
emails.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Add</span>(itm.Value)<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Next</span></p>
<p><span style="color: #006400;">&#8216;create an XmlSerializer and use it to populate a memory stream<br />
</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> xs <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> System.Xml.Serialization.XmlSerializer(<span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">GetType</span>(ArrayList))<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> ms <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> System.IO.MemoryStream<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Try</span><br />
xs.Serialize(ms, emails)<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Catch</span> ex <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> Exception<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Try<br />
</span><span style="color: #006400;"><br />
</span> <span style="color: #006400;"> &#8216;rewind the stream</span><br />
ms.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Seek</span>(0, 0)</p>
<p><span style="color: #006400;"> &#8216;read the stream to string, I use a StreamReader to take advantage of ReadToEnd</span><br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> sr <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> System.IO.StreamReader(ms)<br />
<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"> Dim</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #000000;">str</span></span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">String</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> sr.ReadToEnd</p>
<p><span style="color: #006400;"> &#8216;now we can save the string to a database</span></p>
<p><span style="font-family: Arial;"><span style="font-size: x-small;"><span style="color: #000000;">Here is the code that re-populates the list from an XML string</span><br />
</span></span><br />
&#8216;we&#8217;ll start with a string of xml called <span style="color: #ff0000;">str</span>. I&#8217;ll assume it&#8217;s already pulled from the database</p>
<pre><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"><span style="color: #006400;">       'To convert a string to a stream  we have to convert to a byte array first.
       'aStr is str converted to an array of bytes</span>
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> uniEncoding <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> UnicodeEncoding()
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> aStr <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Byte</span>() <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> uniEncoding.GetBytes(<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">str</span>)

<span style="color: #006400;">      'wrtie the byte array to a stream and rewind it</span>

        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> ms <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> System.IO.MemoryStream
        ms.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Write</span>(aStr, 0, aStr.Length)
        ms.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Seek</span>(0, 0)

<span style="color: #006400;">      'de-serialize from xml to an array of strings
</span>        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> emails <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> ArrayList()
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> xs <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">New</span> System.Xml.Serialization.XmlSerializer(<span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">GetType</span>(ArrayList))

        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Try</span>
            emails <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> xs.Deserialize(ms)
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Catch</span> ex <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> Exception
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Try</span>

<span style="color: #006400;">      'load the array into the listbox's items collection</span>
        ListBox1.Items.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Clear</span>()
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">For</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Each</span> itm <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Object</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">In</span> emails
            ListBox1.Items.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Add</span>(itm.ToString)
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Next</span></span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/serializing-and-de-serializing-a-listbox-to-xml/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Insert with FormView using Linq</title>
		<link>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/</link>
		<comments>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:05:40 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Formview]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=23</guid>
		<description><![CDATA[I had a wierd error trying to insert data using a formview today.
The jist is this: the formview was trying to use an empty string for an int field instead of Nothing.
Here is the error I saw, helpful huh?

Failed to set one or more properties on type xxxxxxx  Ensure that the input values are valid and can [...]]]></description>
			<content:encoded><![CDATA[<p>I had a wierd error trying to insert data using a formview today.</p>
<p>The jist is this: the formview was trying to use an empty string for an int field instead of Nothing.<br />
Here is the error I saw, helpful huh?</p>
<p><span></p>
<h2><em><span style="color: #a52a2a;">Failed to set one or more properties on type xxxxxxx  Ensure that the input values are valid and can be converted to the corresponding property types.</span></em></h2>
<p></span></p>
<p>The fields are allowed to be null but the formview just isn&#8217;t smart enough to use nothing instead of &#8220;&#8221;.</p>
<p>My workaround was simple and flexible enough to be re-used so I figured I would post it here.<br />
I simply hijack the formview&#8217;s onInserting and replaced &#8220;&#8221; with Nothing for each field.</p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">Protected</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span><span style="font-size: x-small;"> formView1_ItemInserting(</span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> sender </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Object</span><span style="font-size: x-small;">, </span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> e </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> System.Web.UI.WebControls.FormViewInsertEventArgs)</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> For</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Each</span><span style="font-size: x-small;"> o </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> DictionaryEntry </span><span style="color: #0000ff; font-size: x-small;">In</span><span style="font-size: x-small;"> e.Values<br />
</span><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> o.Value = </span><span style="color: #a31515; font-size: x-small;">&#8220;&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Then</span><span style="font-size: x-small;"> e.Values(o.Key) = </span><span style="color: #0000ff; font-size: x-small;">Nothing<br />
</span><span style="color: #0000ff; font-size: x-small;"> Next</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/insert-with-formview-using-linq/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>switch to ssl automatically</title>
		<link>http://www.npathweb.com/2009/02/05/switch-to-ssl-automatically/</link>
		<comments>http://www.npathweb.com/2009/02/05/switch-to-ssl-automatically/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:04:06 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[HTTPS]]></category>
		<category><![CDATA[SSL]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=21</guid>
		<description><![CDATA[In this post I&#8217;ll explain how I transparently switch from http to https
This same snipit can be put on any page as is and forces certain pages to be https. The nice thing about it is that the user can not edit the url back to http on a page that has this. All I [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll explain how I transparently switch from http to https</p>
<p>This same snipit can be put on any page as is and forces certain pages to be https. The nice thing about it is that the user can not edit the url back to http on a page that has this. All I did was put it on the login page and payment page.</p>
<p>On page load the server examines the Request.IsSecureConnection flag and redirects if not secure. It&#8217;s that simple. To make it a re-useble snipit I get the page name dynamically.</p>
<p>Be sure not to include the slash after your top level domain.</p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Not</span><span style="font-size: x-small;"> Page.IsPostBack </span><span style="color: #0000ff; font-size: x-small;">Then</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Not</span><span style="font-size: x-small;"> Request.IsSecureConnection </span><span style="color: #0000ff; font-size: x-small;">Then</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="font-size: x-small;"> Response.Redirect(</span><span style="color: #800000; font-size: x-small;">&#8220;https://www.yourhostname.com&#8221;</span><span style="font-size: x-small;"> &amp; Request.Url.PathAndQuery.ToString)</span></p>
<p><span style="color: #0000ff; font-size: x-small;"> End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/switch-to-ssl-automatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ajax update panels and the errors that love them.</title>
		<link>http://www.npathweb.com/2009/02/05/ajax-update-panels-and-the-errors-that-love-them/</link>
		<comments>http://www.npathweb.com/2009/02/05/ajax-update-panels-and-the-errors-that-love-them/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:02:31 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=20</guid>
		<description><![CDATA[I have been using ajax a lot lately in my current project. I have noticed an annoying quirk. When a runtime error happens the page appears to hang. temprarily dissabling the update panel quickly reveals that the page isn&#8217;t really stuck, but there is an error that ajax is ignoring.
I did some research and found [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using ajax a lot lately in my current project. I have noticed an annoying quirk. When a runtime error happens the page appears to hang. temprarily dissabling the update panel quickly reveals that the page isn&#8217;t really stuck, but there is an error that ajax is ignoring.</p>
<p>I did some research and found a few good examples of how to handle the errors but most were in C# and some didn&#8217;t work in Firefox. Imagine that!</p>
<p>Being a VB guy I decided to post a very stipped down sample of how it works.</p>
<p>The lowdown: The script manager is wired to an event handler that passes the exeption info to the client side java script.  Then we put some client side java script in to display the message.</p>
<pre><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;">&lt;%@ Page Language=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"VB"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">%</span>&gt;

&lt;!DOCTYPE html <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">PUBLIC</span> <span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"-//W3C//DTD XHTML 1.0 Transitional//EN"</span> <span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span>&gt;

&lt;script runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span>&gt;

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Protected</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span> SuccessProcessClick_Handler(<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> sender <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Object</span>, <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> e <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> System.EventArgs)
        <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'a successful click</span>
        UpdatePanelMessage.Text <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"The asynchronous postback completed successfully."</span>

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span>

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Protected</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span> ScriptManager1_AsyncPostBackError(<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> sender <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Object</span>, <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> e <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> System.Web.UI.AsyncPostBackErrorEventArgs)

        <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'this creates an exception in the client side Javascript. the exeption will be handled on the client side.</span>
        ScriptManager1.AsyncPostBackErrorMessage <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> e.Exception.Message

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span>

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Protected</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span> ErrorProcessClick_Handler(<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> sender <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Object</span>, <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">ByVal</span> e <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> System.EventArgs)

        <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'cause an error on this click</span>
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> x <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Integer</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> 0
        <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Dim</span> y <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">As</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Integer</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> 10 <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span> x

    <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">End</span> <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">Sub</span>
&lt;/script&gt;

&lt;html xmlns=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"http://www.w3.org/1999/xhtml"</span>&gt;
&lt;head runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span>&gt;
    &lt;title&gt;Untitled Page&lt;/title&gt;
      &lt;style type=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"text/css"</span>&gt;
   #AlertDiv{
     position:relative;
     visibility: hidden;
     background-color:maroon;
     color:White;
     width:500px;

    }

    &lt;/style&gt;
&lt;/head&gt;
&lt;body &gt;
    &lt;form id=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"form1"</span> runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span>&gt;
        &lt;div&gt;
            &lt;asp:ScriptManager ID=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ScriptManager1"</span> runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span>
                onasyncpostbackerror=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ScriptManager1_AsyncPostBackError"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;

            &lt;script type=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"text/javascript"</span> language=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"javascript"</span>&gt;
              <span style="color: #008000;"> // this <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">is</span> the client side script that will handle the <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">error</span> passed from the server.</span>
                var divElem <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'AlertDiv';</span>
                var messageElem <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'AlertMessage';</span>
                var bodyTag <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'bodytag';</span>
                Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);

               <span style="color: #008000;">//hide <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">or</span></span> show the <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">error</span></span> div</span>
                <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">function</span> ToggleAlertDiv(visString)
                {

                     var adiv <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> $<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">get</span>(divElem);
                     adiv.style.visibility <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> visString;

                }

                <span style="color: #008000;">//<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">reset</span></span> the <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">error</span></span> div</span>
                <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">function</span> ClearErrorState() {
                     $<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">get</span>(messageElem).innerHTML <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> <span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'';</span>
                     ToggleAlertDiv(<span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'hidden');                     </span>
                }
               <span style="color: #008000;"> //put the <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">error</span></span> text into the div</span>
                <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">function</span> EndRequestHandler(sender, args)
                {
                   <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">if</span> (args.get_error() !<span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> undefined)
                   {
                       var errorMessage <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span> args.get_error().message;
                       args.set_errorHandled(<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">true</span>);
                      ToggleAlertDiv(<span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'visible');</span>
                      <span style="color: #008000;">//errorMessage.<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">split</span></span><span style="color: #008000;">(<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;"><span style="color: #008000;">":"</span></span>,</span>2)[1] <span style="color: #008000;"><span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">=</span></span> </span><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">get</span></span> just the message <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">and</span></span> chop <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">off</span></span> the identifier before the :
                      //</span></span><span style="font-size: 11px; color: black; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">The message iteself <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">is</span></span> the only usefull part <span style="color: #008000;"><span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">to</span></span> </span>the <span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;"><span style="color: #008000;">end</span></span> user.</span>
                      $<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">get</span>(messageElem).innerHTML <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">=</span><span style="font-size: 11px; color: green; font-family: Courier New; background-color: transparent;">'Error:' + errorMessage.split(":",2)[1];</span>

                   }
                }
            &lt;/script&gt;
            &lt;asp:UpdatePanel runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"Server"</span> ID=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"UpdatePanel1"</span>&gt;
                &lt;ContentTemplate&gt;

                  &lt;div id=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"AlertDiv"</span>&gt;

                      &lt;div id=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"AlertMessage"</span>&gt;&lt;/div&gt;

                         &lt;<span style="font-size: 11px; color: blue; font-family: Courier New; background-color: transparent;">input</span> id=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"OKButton"</span> type=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"button"</span> value=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"OK"</span> runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span> onclick=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ClearErrorState()"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;

                  &lt;/div&gt;

                        &lt;asp:Label ID=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"UpdatePanelMessage"</span> runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;&lt;br <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;

                        &lt;asp:Button runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span> ID=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"Button1"</span> Text=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"Submit Successful Async Postback"</span>
                            OnClick=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"SuccessProcessClick_Handler"</span> OnClientClick=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ClearErrorState()"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;
                        &lt;asp:Button runat=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"server"</span> ID=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"Button2"</span> Text=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"Submit Async Postback With Error"</span>
                            OnClick=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ErrorProcessClick_Handler"</span> OnClientClick=<span style="font-size: 11px; color: #666666; font-family: Courier New; background-color: #e4e4e4;">"ClearErrorState()"</span> <span style="font-size: 11px; color: red; font-family: Courier New; background-color: transparent;">/</span>&gt;

                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;

     &lt;/div&gt;
    &lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/ajax-update-panels-and-the-errors-that-love-them/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>email a gridview</title>
		<link>http://www.npathweb.com/2009/02/05/email-a-gridview/</link>
		<comments>http://www.npathweb.com/2009/02/05/email-a-gridview/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 17:00:28 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Gridview]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=18</guid>
		<description><![CDATA[In this post I&#8217;ll discuss how I coerced a gridview control into straight text.  The reason I did this was to send the data from the gridview in an email. An invoice in this case.
At first I figured I could use a div and simply tap in to the inner html. No luck! It&#8217;s not available on the server [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll discuss how I coerced a gridview control into straight text.  The reason I did this was to send the data from the gridview in an email. An invoice in this case.</p>
<p>At first I figured I could use a div and simply tap in to the inner html. No luck! It&#8217;s not available on the server side. I&#8217;d like to avoid the help of Javascript so I kept looking.</p>
<p>I decided to make my own copy of text that is generated when the grid is databound. Every time a row is databound I append the info to my string. This turned out to be pretty flexible. I can pretty much turn the data into anything I want. csv, or a html table. At first I tried plain text with tabs in between. I decided to use an html table as it ended up looking the best.</p>
<p>In the grid&#8217;s row databound event I add &lt;table&gt; if the row is a header row. I close it with &lt;/table&gt; if the row is the footer. For everyting in between I create a &lt;tr&gt; then for each control with &lt;td&gt;</p>
<p>I saved this text in a hidden label that I can call later to be used in the body of an email.</p>
<p>Here is the source code. I use linq to poulate the gridview but you can bind the gridview to any datasource.</p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="font-size: x-small;">&lt;%</span><span style="color: #0000ff; font-size: x-small;">@</span><span style="font-size: x-small;"> </span><span style="color: #a31515; font-size: x-small;">Page</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">Language</span><span style="color: #0000ff; font-size: x-small;">=&#8221;VB&#8221;</span><span style="font-size: x-small;"> %&gt;<br />
</span><span style="color: #0000ff; font-size: x-small;">&lt;!</span><span style="color: #a31515; font-size: x-small;">DOCTYPE</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">html</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">PUBLIC</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">&#8220;-//W3C//DTD XHTML 1.0 Transitional//EN&#8221;</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">&#8220;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#8221;&gt;<br />
&lt;</span><span style="color: #a31515; font-size: x-small;">script</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">Protected</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span><span style="font-size: x-small;"> Page_Load(</span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> sender </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Object</span><span style="font-size: x-small;">, </span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> e </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> System.EventArgs)</span></p>
<p><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Not</span><span style="font-size: x-small;"> Page.IsPostBack </span><span style="color: #0000ff; font-size: x-small;">Then</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #9acd32; font-size: x-small;">&#8216;make some data with Linq</span></p>
<p><span style="color: #0000ff; font-size: x-small;">Dim</span><span style="font-size: x-small;"> myList() = {</span><span style="color: #0000ff; font-size: x-small;">New</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">With</span><span style="font-size: x-small;"> {.Name = </span><span style="color: #a31515; font-size: x-small;">&#8220;Bill&#8221;</span><span style="font-size: x-small;">, .Title = </span><span style="color: #a31515; font-size: x-small;">&#8220;Developer&#8221;</span><span style="font-size: x-small;">, .Age = </span><span style="color: #a31515; font-size: x-small;">&#8220;21&#8243;</span><span style="font-size: x-small;">, .Birthday = </span><span style="color: #a31515; font-size: x-small;">&#8220;9/30&#8243;</span><span style="font-size: x-small;">}, _<br />
</span><span style="color: #0000ff; font-size: x-small;">New</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">With</span><span style="font-size: x-small;"> {.Name = </span><span style="color: #a31515; font-size: x-small;">&#8220;Joe&#8221;</span><span style="font-size: x-small;">, .Title = </span><span style="color: #a31515; font-size: x-small;">&#8220;Tester&#8221;</span><span style="font-size: x-small;">, .Age = </span><span style="color: #a31515; font-size: x-small;">&#8220;23&#8243;</span><span style="font-size: x-small;">, .Birthday = </span><span style="color: #a31515; font-size: x-small;">&#8220;1/3&#8243;</span><span style="font-size: x-small;">}, _<br />
</span><span style="color: #0000ff; font-size: x-small;">New</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">With</span><span style="font-size: x-small;"> {.Name = </span><span style="color: #a31515; font-size: x-small;">&#8220;Tom&#8221;</span><span style="font-size: x-small;">, .Title = </span><span style="color: #a31515; font-size: x-small;">&#8220;Senior Developer&#8221;</span><span style="font-size: x-small;">, .Age = </span><span style="color: #a31515; font-size: x-small;">&#8220;25&#8243;</span><span style="font-size: x-small;">, .Birthday = </span><span style="color: #a31515; font-size: x-small;">&#8220;3/20&#8243;</span><span style="font-size: x-small;">}, _<br />
</span><span style="color: #0000ff; font-size: x-small;">New</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">With</span><span style="font-size: x-small;"> {.Name = </span><span style="color: #a31515; font-size: x-small;">&#8220;Mark&#8221;</span><span style="font-size: x-small;">, .Title = </span><span style="color: #a31515; font-size: x-small;">&#8220;Technician&#8221;</span><span style="font-size: x-small;">, .Age = </span><span style="color: #a31515; font-size: x-small;">&#8220;41&#8243;</span><span style="font-size: x-small;">, .Birthday = </span><span style="color: #a31515; font-size: x-small;">&#8220;6/26&#8243;</span><span style="font-size: x-small;">} _</span></p>
<p><span style="font-size: x-small;">}</span></p>
<p><span style="color: #0000ff; font-size: x-small;">Me</span><span style="font-size: x-small;">.GridView1.DataSource = myList<br />
</span><span style="color: #0000ff; font-size: x-small;">Me</span><span style="font-size: x-small;">.GridView1.DataBind()</span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">Protected</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span><span style="font-size: x-small;"> GridView1_RowDataBound(</span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> sender </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Object</span><span style="font-size: x-small;">, </span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> e </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> System.Web.UI.WebControls.GridViewRowEventArgs)</span></p>
<p><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> e.Row.RowType = DataControlRowType.Header </span><span style="color: #0000ff; font-size: x-small;">Then<br />
</span><span style="font-size: x-small;"> Label1.Text &amp;= vbCrLf &amp; </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;table border=&#8217;0&#8242;cellpadding=&#8217;5&#8242; cellspacing=&#8217;5&#8242;&gt;&#8221;</span><span style="font-size: x-small;"> &amp; vbCrLf<br />
</span><span style="color: #0000ff; font-size: x-small;"> End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> e.Row.RowType &lt;&gt; DataControlRowType.Footer </span><span style="color: #0000ff; font-size: x-small;">Then<br />
</span><span style="font-size: x-small;">Label1.Text &amp;= vbTab &amp; </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;tr&gt;&#8221;</span><span style="font-size: x-small;"> &amp; vbCrLf</span></p>
<p><span style="color: #0000ff; font-size: x-small;"> For</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Each</span><span style="font-size: x-small;"> item </span><span style="color: #0000ff; font-size: x-small;">In</span><span style="font-size: x-small;"> e.Row.Controls</span></p>
<p><span style="color: #0000ff; font-size: x-small;"> If</span><span style="font-size: x-small;"> item.visible = </span><span style="color: #0000ff; font-size: x-small;">True</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Then</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="font-size: x-small;"> Label1.Text &amp;= vbTab &amp; vbTab &amp; </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;td&gt;&#8221;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="font-size: x-small;"> Label1.Text &amp;= item.text</span></p>
<p><span style="font-size: x-small;"> Label1.Text &amp;= </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;/td&gt;&#8221;</span><span style="font-size: x-small;"> &amp; vbCrLf</span></p>
<p><span style="color: #0000ff; font-size: x-small;"> End </span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> Next</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="font-size: x-small;">Label1.Text &amp;= vbTab &amp; </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;/tr&gt;&#8221;</span><span style="font-size: x-small;"> &amp; vbCrLf</span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">If</span><span style="font-size: x-small;"> e.Row.RowType = DataControlRowType.Footer </span><span style="color: #0000ff; font-size: x-small;">Then<br />
</span><span style="font-size: x-small;">Label1.Text &amp;= </span><span style="color: #a31515; font-size: x-small;">&#8220;&lt;/table&gt;&#8221;</span><span style="font-size: x-small;"> &amp; vbCrLf<br />
</span><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">If</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">Protected</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span><span style="font-size: x-small;"> Button1_Click(</span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> sender </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Object</span><span style="font-size: x-small;">, </span><span style="color: #0000ff; font-size: x-small;">ByVal</span><span style="font-size: x-small;"> e </span><span style="color: #0000ff; font-size: x-small;">As</span><span style="font-size: x-small;"> System.EventArgs)</span></p>
<p><span style="color: #0000ff; font-size: x-small;">Me</span><span style="font-size: x-small;">.Label2.Text = Server.HtmlEncode(Label1.Text)</span></p>
<p><span style="color: #0000ff; font-size: x-small;">Me</span><span style="font-size: x-small;">.Label1.Visible = </span><span style="color: #0000ff; font-size: x-small;">True</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216; Dim msg As New System.Net.Mail.MailMessage(<a href="mailto:TO@EMAIL.COM">TO@EMAIL.COM</a>, <a href="mailto:FROM@EMAIL.COM">FROM@EMAIL.COM</a>)</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216; msg.Subject = &#8220;Gridview email&#8221;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216; msg.IsBodyHtml = True</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216; msg.Body = Me.Label1.Text</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216;Dim smtp As New System.Net.Mail.SmtpClient</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #008000; font-size: x-small;">&#8216; smtp.Send(msg)</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">End</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">Sub</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">script</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">html</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">xmlns</span><span style="color: #0000ff; font-size: x-small;">=&#8221;http://www.w3.org/1999/xhtml&#8221;&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">head</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">title</span><span style="color: #0000ff; font-size: x-small;">&gt;</span><span style="font-size: x-small;">Untitled Page</span><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">title</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">head</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">body</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">form</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">id</span><span style="color: #0000ff; font-size: x-small;">=&#8221;form1&#8243;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">div</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">id</span><span style="color: #0000ff; font-size: x-small;">=&#8221;div1&#8243;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">GridView</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">ID</span><span style="color: #0000ff; font-size: x-small;">=&#8221;GridView1&#8243;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">onrowdatabound</span><span style="color: #0000ff; font-size: x-small;">=&#8221;GridView1_RowDataBound&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">AutoGenerateColumns</span><span style="color: #0000ff; font-size: x-small;">=&#8221;False&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">Columns</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;"> &lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">BoundField</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">DataField</span><span style="color: #0000ff; font-size: x-small;">=&#8221;name&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">HeaderText</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Name&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;<br />
</span><span style="color: #0000ff; font-size: x-small;"> &lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">BoundField</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">DataField</span><span style="color: #0000ff; font-size: x-small;">=&#8221;age&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">HeaderText</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Age&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;<br />
</span><span style="color: #0000ff; font-size: x-small;"> &lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">BoundField</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">DataField</span><span style="color: #0000ff; font-size: x-small;">=&#8221;title&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">HeaderText</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Title&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;<br />
</span><span style="color: #0000ff; font-size: x-small;"> &lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">BoundField</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">DataField</span><span style="color: #0000ff; font-size: x-small;">=&#8221;birthday&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">HeaderText</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Birthday&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">Columns</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">GridView</span><span style="color: #0000ff; font-size: x-small;">&gt;</span><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">Button</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">ID</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Button1&#8243;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">Text</span><span style="color: #0000ff; font-size: x-small;">=&#8221;capture this ^&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">onclick</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Button1_Click&#8221;</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">br</span><span style="font-size: x-small;"> </span><span style="color: #0000ff; font-size: x-small;">/&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">Label</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">ID</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Label1&#8243;</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">Visible</span><span style="color: #0000ff; font-size: x-small;">=&#8221;False&#8221;&gt;&lt;/</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">Label</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">pre</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">Label</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">ID</span><span style="color: #0000ff; font-size: x-small;">=&#8221;Label2&#8243;</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">runat</span><span style="color: #0000ff; font-size: x-small;">=&#8221;server&#8221;</span><span style="color: #000000; font-size: x-small;"> </span><span style="color: #ff0000; font-size: x-small;">Visible</span><span style="color: #0000ff; font-size: x-small;">=&#8221;true&#8221;&gt;&lt;/</span><span style="color: #a31515; font-size: x-small;">asp</span><span style="color: #0000ff; font-size: x-small;">:</span><span style="color: #a31515; font-size: x-small;">Label</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">pre</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">div</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="font-size: x-small;"> </span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">form</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">body</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
<p><span style="color: #0000ff; font-size: x-small;">&lt;/</span><span style="color: #a31515; font-size: x-small;">html</span><span style="color: #0000ff; font-size: x-small;">&gt;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/email-a-gridview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How does the adrotator control&#8217;s imrpessions property work?</title>
		<link>http://www.npathweb.com/2009/02/05/how-does-the-adrotator-controls-imrpessions-property-work/</link>
		<comments>http://www.npathweb.com/2009/02/05/how-does-the-adrotator-controls-imrpessions-property-work/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 16:51:30 +0000</pubDate>
		<dc:creator>B.Harding</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Ad Rotator]]></category>
		<category><![CDATA[ASP.net]]></category>

		<guid isPermaLink="false">http://www.npathweb.com/blog/?p=7</guid>
		<description><![CDATA[
The msdn documentation was a little hazy on this subject. Here it is as I understand it&#8230;.
Lets start from the beginning; and adrotator will take a list of images and rotate through them every time the page loads. Some ads may need to appear more often than others. That is where the Impressions property comes in. It [...]]]></description>
			<content:encoded><![CDATA[<div class="itemBodyStyle">
<p>The msdn documentation was a little hazy on this subject. Here it is as I understand it&#8230;.</p>
<p>Lets start from the beginning; and adrotator will take a list of images and rotate through them every time the page loads. Some ads may need to appear more often than others. That is where the Impressions property comes in. It allows to give some ads more weight than others. Perhaps one person is paying more for the ad.</p>
<p>OK, so how do we use it? if every image should be weighted equally just set it to 1. Other wise you need to figure out the ratio. To figure it out you add up all the impression values in the file. Each ads ratio is it&#8217;s impression value divided by the total.</p>
<p>So if there were three ads in the file and they looked like this:</p>
<p>ad 1 imressions = 1<br />
ad 2 impressions=2<br />
ad 2 impressions =2</p>
<p>The total is 5. Ad 1 will be show 1 out of 5 times. Ad 2 will be shown 2 out of 5 times and so on.</p>
<p>I like to work in percentages. To do this just divy up the ads until we get to 100%.</p>
<p>Ad 1 impressions = 20%<br />
Ad 2 impressions= 40%<br />
ad 3 impressions= 40%</p>
<p>Just make sure they all ad up to 100 and your done.  The percentage is the number of impressions.  1, 2,2 is actually the same as 20, 40, 40 so why not base it on 100 so it&#8217;s easier to figure out?</p>
<p>Good Luck.</p>
<p>P.S. I saw a blog somewhere that wrapped an adrotator in a UpdatePanel that pdated on a timer. Interesting. Quicker than flash and more flexible than an animated gif. I&#8217;ll be filing that in the back of my mind.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.npathweb.com/2009/02/05/how-does-the-adrotator-controls-imrpessions-property-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
