<?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>Blog of developer Mikkel Ovesen &#187; control</title>
	<atom:link href="http://blog.ovesens.net/tag/control/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ovesens.net</link>
	<description>My thoughts, stuff I need to remember or things I just want to share with the world</description>
	<lastBuildDate>Thu, 19 Jan 2012 11:55:29 +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>New ASP.NET Charting Control</title>
		<link>http://blog.ovesens.net/2008/11/new-asp-net-charting-control/</link>
		<comments>http://blog.ovesens.net/2008/11/new-asp-net-charting-control/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 10:48:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[webforms]]></category>

		<guid isPermaLink="false">/post/2008/11/26/New-ASPNET-Charting-Control.aspx</guid>
		<description><![CDATA[Microsoft released a free ASP.NET charting controls. Read more about it here: http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx Or take a qucik look directly on these following link: Microsoft recently released a cool new ASP.NET server control &#8211; &#60;asp:chart /&#62; &#8211; that can be used &#8230; <a href="http://blog.ovesens.net/2008/11/new-asp-net-charting-control/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Microsoft released a free ASP.NET charting controls.
</p>
<p>
Read more about it here:
</p>
<p>
<a href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx">http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx</a>
</p>
<p>
Or take a qucik look directly on these following link:
</p>
<p>
Microsoft recently released a cool new ASP.NET server control &#8211; &lt;asp:chart /&gt; &#8211; that can be used for free with ASP.NET 3.5 to enable rich browser-based charting scenarios:
</p>
<ul>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=130f7986-bf49-4fe5-9ca8-910ae6ea442c&amp;DisplayLang=en" target="_blank">Download the free Microsoft Chart Controls</a> </li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?familyid=1D69CE13-E1E5-4315-825C-F14D33A303E9&amp;displaylang=en" target="_blank">Download the VS 2008 Tool Support for the Chart Controls</a> </li>
<li><a href="http://code.msdn.microsoft.com/mschart/Release/ProjectReleases.aspx?ReleaseId=1591" target="_blank">Download the Microsoft Chart Controls Samples</a> </li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=EE8F6F35-B087-4324-9DBA-6DD5E844FD9F&amp;displaylang=en" target="_blank">Download the Microsoft Chart Controls Documentation</a> </li>
<li><a href="http://social.msdn.microsoft.com/Forums/en-US/MSWinWebChart/threads/" target="_blank">Visit the Microsoft Chart Control Forum</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/11/new-asp-net-charting-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Ajax uploader plugin (with progress bar!)</title>
		<link>http://blog.ovesens.net/2008/11/jquery-ajax-uploader-plugin-with-progress-bar/</link>
		<comments>http://blog.ovesens.net/2008/11/jquery-ajax-uploader-plugin-with-progress-bar/#comments</comments>
		<pubDate>Wed, 26 Nov 2008 10:20:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">/post/2008/11/26/jQuery-Ajax-uploader-plugin-(with-progress-bar!).aspx</guid>
		<description><![CDATA[Original post here: http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; Do your web applications ever involve letting the user upload a file? If so, how&#8217;s the end-user experience: do you show a nice progress bar during the upload, or do you just leave the user &#8230; <a href="http://blog.ovesens.net/2008/11/jquery-ajax-uploader-plugin-with-progress-bar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Original post here:
</p>
<p>
<a href="http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/">http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/</a>
</p>
<p>
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
</p>
<p>
Do your web applications ever involve letting the user upload a file? If so, how&rsquo;s the end-user experience: do you show a nice progress bar during the upload, or do you just leave the user waiting for minutes, with no clue when (if ever) the upload will complete?
</p>
<p>
Please show a progress bar, otherwise users will be justified in hating you. Check out this video to see one way it can work:
</p>
<div align="center" style="margin-bottom: 1em">
<br />
<strong style="display: none">If you&rsquo;re not seeing a video here, your feed reader is hiding it. <a href="http://blog.codeville.net/2008/11/24/jquery-ajax-uploader-plugin-with-progress-bar/">View this post in a browser</a> to see the video.</strong>
</div>
<p>
Those of you who attended my ASP.NET MVC talk at DDD7 last weekend might recognise this <img class="wp-smiley" src="http://blog.codeville.net/wp-includes/images/smilies/icon_wink.gif" alt=";)" width="15" height="15" />
</p>
<p>
To create this behaviour, I implemented a simple jQuery plugin that replaces normal &lt;input type=&rdquo;file&rdquo;/&gt; elements with funky Ajaxy asynchronous uploader widgets. Behind the scenes, it uses the excellent <a href="http://swfupload.org/" target="_blank">SWFUpload</a> library. All the clever stuff is in SWFUpload; all I did is set up the progress bar / cancellation behaviours, and make it easier to use if you&rsquo;re already using jQuery.
</p>
<p>
Notice that it still works if the user doesn&rsquo;t have JavaScript running in their browser. It gracefully degrades to &ldquo;traditional&rdquo; &lt;input type=&rdquo;file&rdquo;/&gt; behaviour. This is known as <em>progressive enhancement </em>or <em>unobtrusive JavaScript</em>.
</p>
<h4>Download</h4>
<p>
Here are all the files you need to accomplish this: <a href="http://blog.codeville.net/blogfiles/2008/November/jquery-asyncUpload-0.1.zip" target="_blank">Download jQuery-asyncUpload-0.1.js</a><strong>. </strong>
</p>
<h4>Setup instructions</h4>
<p>
Uploading files via Ajax, by nature, involves setting things up both on the server and on the client. <strong>The most reliable way to get this working successfully in your own app is to download the demo ASP.NET MVC project (see the end of this post) and copy the relevant aspects of its workings into your own app.</strong>
</p>
<p>
Nonetheless, here is an outline of the steps needed to get <strong>jQuery-asyncUpload-0.1.js</strong> working in your app, assuming you&rsquo;ve already got jQuery in there:
</p>
<p>
1.&nbsp; Add <strong>jQuery-asyncUpload-0.1.js</strong>, <strong>swfupload.js</strong>, and <strong>swfupload.swf</strong> to your project. In an ASP.NET MVC app, you might like to put these in <strong>/Scripts</strong>.
</p>
<p>
2.&nbsp; Add script tags to reference the JavaScript files.
</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml">
<span style="color: #009900"><span style="font-weight: bold; color: black">&lt;head<span style="font-weight: bold; color: black">&gt;
</span></span></span>    <span style="color: #009900"><span style="color: #808080; font-style: italic">&lt;!-- Adjust the file paths as needed for your project --&gt;
</span></span>    <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;script</span> <span style="color: #000066">src</span>=<span style="color: #ff0000">&quot;/Scripts/jquery-1.2.6.min.js&quot;</span><span style="font-weight: bold; color: black">&gt;</span></span><span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/script<span style="font-weight: bold; color: black">&gt;
</span></span></span>    <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;script</span> <span style="color: #000066">src</span>=<span style="color: #ff0000">&quot;/Scripts/swfupload.js&quot;</span><span style="font-weight: bold; color: black">&gt;</span></span><span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/script<span style="font-weight: bold; color: black">&gt;
</span></span></span>    <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;script</span> <span style="color: #000066">src</span>=<span style="color: #ff0000">&quot;/Scripts/jquery-asyncUpload-0.1.js&quot;</span><span style="font-weight: bold; color: black">&gt;</span></span><span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/script<span style="font-weight: bold; color: black">&gt;
</span></span></span><span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/head<span style="font-weight: bold; color: black">&gt;</span></span></span>
</pre>
</div>
</div>
<p>
3.&nbsp; Add an old-style HTML file upload control to one of your pages:
</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml">
<span style="color: #009900"><span style="font-weight: bold; color: black">&lt;input</span> <span style="color: #000066">type</span>=<span style="color: #ff0000">&quot;file&quot;</span> <span style="color: #000066">id</span>=<span style="color: #ff0000">&quot;yourID&quot;</span> <span style="color: #000066">name</span>=<span style="color: #ff0000">&quot;yourID&quot;</span> <span style="font-weight: bold; color: black">/&gt;</span></span>
</pre>
</div>
</div>
<p>
4. Add a jQuery statement that replaces this file upload control with an asynchronous uploader when JavaScript is available:
</p>
<div class="wp_syntax">
<div class="code">
<pre class="javascript">
&lt;script&gt;
$<span style="color: #66cc66">(</span><span style="font-weight: bold; color: #003366">function</span><span style="color: #66cc66">(</span><span style="color: #66cc66">)</span> <span style="color: #66cc66">{
</span>        $<span style="color: #66cc66">(</span><span style="color: #3366cc">&quot;#yourID&quot;</span><span style="color: #66cc66">)</span>.<span style="color: #006600">makeAsyncUploader</span><span style="color: #66cc66">(</span><span style="color: #66cc66">{
</span>            upload_url: <span style="color: #3366cc">&quot;/Home/AsyncUpload&quot;</span>,
flash_url: <span style="color: #3366cc">&#39;/Scripts/swfupload.swf&#39;</span>,
button_image_url: <span style="color: #3366cc">&#39;/Scripts/blankButton.png&#39;
</span>        <span style="color: #66cc66">}</span><span style="color: #66cc66">)</span>;
<span style="color: #66cc66">}</span><span style="color: #66cc66">)</span>;
&lt;/script&gt;
</pre>
</div>
</div>
<p>
These options are explained later in this blog post. You must make sure to correctly reference the location of <strong>swfupload.swf</strong>, and put a button image wherever <strong>button_image_url</strong> specifies.
</p>
<p>
5. Add some CSS rules to style the progress bar. I&rsquo;m using the following, though bear in mind it has some nasty hacks to make IE do an inline float properly. CSS gurus might structure this more cleanly.
</p>
<div class="wp_syntax">
<div class="code">
<pre class="css">
DIV<span style="color: #6666ff">.ProgressBar</span> <span style="color: #66cc66">{</span> <span style="font-weight: bold; color: #000000">width</span>: <span style="color: #993333">100px</span>; <span style="font-weight: bold; color: #000000">padding</span>: <span style="color: #993333">0</span>; <span style="font-weight: bold; color: #000000">border</span>: <span style="color: #993333">1px</span> <span style="color: #993333">solid</span> <span style="font-weight: bold; color: #000000">black</span>; <span style="font-weight: bold; color: #000000">margin-right</span>: <span style="color: #993333">1em</span>; <span style="font-weight: bold; color: #000000">height</span>:<span style="color: #6666ff"><span style="color: #993333">.75em</span></span>; margin-left<span style="color: #3333ff">:<span style="color: #993333">1em</span></span>; display<span style="color: #3333ff">:-moz-inline-stack</span>; display<span style="color: #3333ff">:inline-block</span>; zoom<span style="color: #3333ff">:<span style="color: #993333">1</span></span>; *display<span style="color: #3333ff">:inline</span>; <span style="color: #66cc66">}
</span>DIV<span style="color: #6666ff">.ProgressBar</span> DIV <span style="color: #66cc66">{</span> <span style="font-weight: bold; color: #000000">background-color</span>: Green; <span style="font-weight: bold; color: #000000">font-size</span>: <span style="color: #993333">1pt</span>; height<span style="color: #3333ff">:<span style="color: #993333">100</span></span>%; float<span style="color: #3333ff">:left</span>; <span style="color: #66cc66">}
</span>SPAN<span style="color: #6666ff">.asyncUploader</span> OBJECT <span style="color: #66cc66">{</span> <span style="font-weight: bold; color: #000000">position</span>: <span style="color: #993333">relative</span>; <span style="font-weight: bold; color: #000000">top</span>: <span style="color: #993333">5px</span>; <span style="font-weight: bold; color: #000000">left</span>: <span style="color: #993333">10px</span>; <span style="color: #66cc66">}
</span>5. At this point, check you have something working. The visitor should now be able to select a file to upload, and should immediately get an alert box saying &ldquo;Error 404&rdquo; &ndash; that&rsquo;s because you&rsquo;ve configured the control to do an asynchronous upload to /Home/AsyncUpload, but your web app probably doesn&rsquo;t have anything at that URL.
</pre>
</div>
</div>
<p>
Also, if you use FireBug to inspect the DOM, you&rsquo;ll see that your &lt;input type=&rdquo;file&rdquo; /&gt; has been dynamically replaced with the following:
</p>
<div class="wp_syntax">
<div class="code">
<pre class="xml">
<span style="color: #009900"><span style="font-weight: bold; color: black">&lt;span</span> <span style="color: #000066">class</span>=<span style="color: #ff0000">&quot;asyncUploader&quot;</span><span style="font-weight: bold; color: black">&gt;
</span></span>   <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;div</span> <span style="color: #000066">class</span>=<span style="color: #ff0000">&quot;ProgressBar&quot;</span> <span style="color: #000066">style</span>=<span style="color: #ff0000">&quot;display: none;&quot;</span><span style="font-weight: bold; color: black">&gt;</span></span>
<span style="color: #009900"><span style="color: #808080; font-style: italic">&lt;!-- This is the progress bar itself - you can style it with CSS --&gt;
</span></span>   <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/div<span style="font-weight: bold; color: black">&gt;
</span></span></span>   <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;object</span> <span style="color: #000066">type</span>=<span style="color: #ff0000">&quot;application/x-shockwave-flash&quot;</span> ... <span style="font-weight: bold; color: black">&gt;
</span></span>       ... SWF config here ...
<span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/object<span style="font-weight: bold; color: black">&gt;
</span></span></span>   <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;input</span> <span style="color: #000066">type</span>=<span style="color: #ff0000">&quot;hidden&quot;</span> <span style="color: #000066">name</span>=<span style="color: #ff0000">&quot;yourID_filename&quot;</span><span style="font-weight: bold; color: black">/&gt;
</span></span>   <span style="color: #009900"><span style="font-weight: bold; color: black">&lt;input</span> <span style="color: #000066">type</span>=<span style="color: #ff0000">&quot;hidden&quot;</span> <span style="color: #000066">name</span>=<span style="color: #ff0000">&quot;yourID_guid&quot;</span><span style="font-weight: bold; color: black">/&gt;
</span></span><span style="color: #009900"><span style="font-weight: bold; color: black">&lt;/span<span style="font-weight: bold; color: black">&gt;</span></span></span>
</pre>
</div>
</div>
<p>
Those two hidden inputs let you keep track of any file that was asynchronously uploaded.
</p>
<p>
6. Work on your web app so that it *does* handle file uploads to <strong>/Home/AsyncUpload</strong> (or whatever URL you&rsquo;ve configured in step 4). The handler should save the uploaded file to disk, then return a unique token, such as a GUID or filename, to will identify the file you just uploaded. See the demo project for a simple way to do this using ASP.NET MVC.
</p>
<p>
7. When the containing form is finally submitted, check whether a file was sent with the request. This will happen if the user doesn&rsquo;t have JavaScript enabled, as they&rsquo;ll revert to traditional uploading behaviour. Also check for the hidden inputs called <strong>yourID_guid</strong> and <strong>yourID</strong><strong>_filename</strong> &ndash; these will be populated if the visitor *does* have JavaScript enabled, and reflect any file that was uploaded asynchronously.
</p>
<h4>Further configuration</h4>
<p>
The asynchronous uploader plugin has plenty of properties you can configure in step 4 above:
</p>
<table border="1" cellspacing="0" cellpadding="2" width="600">
<tbody>
<tr>
<td width="200" valign="top"><strong>Property</strong></td>
<td width="200" valign="top"><strong>Meaning</strong></td>
<td width="200" valign="top"><strong>Example</strong></td>
</tr>
<tr>
<td width="200" valign="top">flash_url</td>
<td width="200" valign="top">Location of swfupload.swf</td>
<td width="200" valign="top">&ldquo;/Scripts/swfupload.swf&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">upload_url</td>
<td width="200" valign="top">URL to which files will be asynchronously uploaded</td>
<td width="200" valign="top">&ldquo;/Home/AsyncUpload&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">file_size_limit</td>
<td width="200" valign="top">Files above this size will be rejected before uploading even begins</td>
<td width="200" valign="top">&ldquo;3 MB&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">file_types</td>
<td width="200" valign="top">&ldquo;Select files&rdquo; popup will only show files of this type</td>
<td width="200" valign="top">&ldquo;*.jpg, *.gif&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">file_types_description</td>
<td width="200" valign="top">&ldquo;Select files&rdquo; popup will use this caption to describe the selectable file types</td>
<td width="200" valign="top">&ldquo;All images&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">button_image_url</td>
<td width="200" valign="top">Location of an image to be used for the &ldquo;Choose file&rdquo; button</td>
<td width="200" valign="top">&ldquo;blankButton.png&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">button_image_width, button_image_height</td>
<td width="200" valign="top">Dimensions of &ldquo;Choose file&rdquo; button</td>
<td width="200" valign="top">109</td>
</tr>
<tr>
<td width="200" valign="top">button_text</td>
<td width="200" valign="top">Text that appears on the &ldquo;Choose file&rdquo; button</td>
<td width="200" valign="top">&quot;&lt;font face=&rsquo;Arial&rsquo; size=&rsquo;13pt&rsquo;&gt;Choose file&lt;/font&gt;&quot;</td>
</tr>
<tr>
<td width="200" valign="top">disableDuringUpload</td>
<td width="200" valign="top">Elements matching this jQuery selector will be disabled while an upload is in progress (useful to prevent form submission during async upload).</td>
<td width="200" valign="top">&ldquo;INPUT[type=&rsquo;submit&rsquo;]&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">existingFilename</td>
<td width="200" valign="top">Prepopulates the control with the name of a file already uploaded (useful when retaining state across multiple posts)</td>
<td width="200" valign="top">&ldquo;somefile.zip&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">existingGuid</td>
<td width="200" valign="top">Prepopulates the control with the arbitrary unique token you&rsquo;ve given to a file already uploaded (useful when retaining state across multiple posts)</td>
<td width="200" valign="top">&ldquo;ec42555e-bfe7-45b0-87bf-36b1299f0398&rdquo;</td>
</tr>
<tr>
<td width="200" valign="top">existingFileSize</td>
<td width="200" valign="top">Prepopulates the control with the size, in bytes, of a file already uploaded (useful when retaining state across multiple posts)</td>
<td width="200" valign="top">548293</td>
</tr>
<tr>
<td width="200" valign="top">debug</td>
<td width="200" valign="top">Turns on SWFUpload&rsquo;s debugging console</td>
<td width="200" valign="top">true</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/11/jquery-ajax-uploader-plugin-with-progress-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic controls in ASP.NET</title>
		<link>http://blog.ovesens.net/2008/11/dynamic-controls-in-asp-net/</link>
		<comments>http://blog.ovesens.net/2008/11/dynamic-controls-in-asp-net/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 19:42:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[usercontrol]]></category>

		<guid isPermaLink="false">/post/2008/11/25/Dynamic-controls-in-ASPNET.aspx</guid>
		<description><![CDATA[As many articles point out it is important to load dynamic control in the Init event of the life cycle. This is important if you want to preserve the view state. Another thing I found out&#8230; you need to instantiate &#8230; <a href="http://blog.ovesens.net/2008/11/dynamic-controls-in-asp-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
As many articles point out it is important to load dynamic control in the Init event of the life cycle. This is important if you want to preserve the view state.
</p>
<p>
Another thing I found out&#8230; you need to instantiate the control, add it to a ControlCollection and then set the properties of the control. If you set the properties before it is added to a ControlCollection. The view state does not work.
</p>
<h2>This is wrong</h2>
<p>
BaseProductControl<font size="2"> control = (<font color="#2b91af"><font color="#2b91af">BaseProductControl</font></font>)<font color="#0000ff"><font color="#0000ff">this</font></font>.Page.LoadControl(product.ViewControl);<br />
control.ProductId = productId;<br />
</font><font size="2">ProductViewPlaceHolder.Controls.Add(control);</font>
</p>
<h2>This will work</h2>
<p><font size="2" color="#2b91af"><font size="2" color="#2b91af"></p>
<p>
BaseProductControl<font size="2"> control = (</font><font size="2" color="#2b91af"><font size="2" color="#2b91af">BaseProductControl</font></font><font size="2">)</font><font size="2" color="#0000ff"><font size="2" color="#0000ff">this</font></font><font size="2">.Page.LoadControl(product.ViewControl);<br />
ProductViewPlaceHolder.Controls.Add(control);<br />
control.ProductId = productId;</font><font size="2"></font>
</p>
<p></font></font></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2008/11/dynamic-controls-in-asp-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I: Build a Custom ASP.NET AJAX Server Control?</title>
		<link>http://blog.ovesens.net/2007/09/how-do-i-build-a-custom-asp-net-ajax-server-control/</link>
		<comments>http://blog.ovesens.net/2007/09/how-do-i-build-a-custom-asp-net-ajax-server-control/#comments</comments>
		<pubDate>Sat, 29 Sep 2007 13:50:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[control]]></category>

		<guid isPermaLink="false">/post/2007/09/29/How-Do-I-Build-a-Custom-ASPNET-AJAX-Server-Control.aspx</guid>
		<description><![CDATA[Original post here: http://www.asp.net/learn/ajax-videos/video-170.aspx &#8212; Learn how to create a custom Web server control with ASP.NET AJAX functionality using the AJAX extensions in the Microsoft AJAX Library. This video walks you through both the server-side .NET code and the client-side &#8230; <a href="http://blog.ovesens.net/2007/09/how-do-i-build-a-custom-asp-net-ajax-server-control/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Original post here:</p>
<p><a title="http://www.asp.net/learn/ajax-videos/video-170.aspx" href="http://www.asp.net/learn/ajax-videos/video-170.aspx">http://www.asp.net/learn/ajax-videos/video-170.aspx</a></p>
<p>&#8212;</p>
<p>Learn how to create a custom Web server control with ASP.NET AJAX functionality using the AJAX extensions in the Microsoft AJAX Library. This video walks you through both the server-side .NET code and the client-side JavaScript code, and provides an explanation of the â€˜prototypeâ€™ concept. The custom ASP.NET AJAX control can then be used in an .aspx page like any other server control.</p>
<p>View video: <a href="/wp-content/uploads/archive/WinVideo-ASP-AJAXCustomAJAXControl.wmv">WinVideo-ASP-AJAXCustomAJAXControl.wmv (12.85 mb)</a></p>
<p><a href="/wp-content/uploads/archive/WinVideo-ASP-AJAXCustomAJAXControl.wmv"><img src="http://static.asp.net/asp.net/images/videos/video-170.png" alt="Play Video" width="264" height="156" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2007/09/how-do-i-build-a-custom-asp-net-ajax-server-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How Do I: Build Custom Server Controls that Work With or Without ASP.NET AJAX?</title>
		<link>http://blog.ovesens.net/2007/09/how-do-i-build-custom-server-controls-that-work-with-or-without-asp-net-ajax/</link>
		<comments>http://blog.ovesens.net/2007/09/how-do-i-build-custom-server-controls-that-work-with-or-without-asp-net-ajax/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 14:37:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[control]]></category>
		<category><![CDATA[usercontrol]]></category>

		<guid isPermaLink="false">/post/2007/09/19/How-Do-I-Build-Custom-Server-Controls-that-Work-With-or-Without-ASPNET-AJAX.aspx</guid>
		<description><![CDATA[View original post here: http://www.asp.net/learn/ajax-videos/video-186.aspx &#8212; Do you have an idea for a custom server control that should be able to work without ASP.NET AJAX, yet could take advantage of ASP.NET AJAX if it is available? In&#160;this video we learn &#8230; <a href="http://blog.ovesens.net/2007/09/how-do-i-build-custom-server-controls-that-work-with-or-without-asp-net-ajax/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="left_video_column_wide">
View original post here:<br />
<a href="http://www.asp.net/learn/ajax-videos/video-186.aspx">http://www.asp.net/learn/ajax-videos/video-186.aspx</a>
</div>
<div class="left_video_column_wide">
&#8212;
</div>
<div class="left_video_column_wide">
<a href="http://download.microsoft.com/download/3/0/f/30f85549-1b3b-4ce6-ab28-209b5c874c73/WinVideo-ASP-AJAXEnableYourExistingCustomControl.wmv"><img class="thumbnail_264_video" src="http://static.asp.net/asp.net/images/videos/video-186.png" alt="Play Video" width="264" height="156" /></a>
</div>
<div class="right_video_column_wide">
<p>
Do you have an idea for a custom server control that should be able to work without ASP.NET AJAX, yet could take advantage of ASP.NET AJAX if it is available? In&nbsp;this video we learn how to build a custom server control that does not reference the ASP.NET AJAX assembly, but uses Reflection to &ldquo;play nice&rdquo; with the ASP.NET AJAX UpdatePanel.
</p>
<p>
<em>Presented by Chris Pels</em>
</p>
<p>
Duration: 19 minutes, 21 seconds
</p>
<p>
Date: 9 July 2007
</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2007/09/how-do-i-build-custom-server-controls-that-work-with-or-without-asp-net-ajax/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a GridView with Resizable Column Headers</title>
		<link>http://blog.ovesens.net/2007/09/creating-a-gridview-with-resizable-column-headers/</link>
		<comments>http://blog.ovesens.net/2007/09/creating-a-gridview-with-resizable-column-headers/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 14:31:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[client side]]></category>
		<category><![CDATA[control]]></category>

		<guid isPermaLink="false">/post/2007/09/19/Creating-a-GridView-with-Resizable-Column-Headers.aspx</guid>
		<description><![CDATA[View the original post here: http://mattberseth.com/blog/2007/08/creating_a_gridview_with_resiz.html &#8212; I was recently reading Dan Wahlin&#8217;s excellent &#8216;How To&#8217; for creating a GridView extender control.  While I was going through his code samples, I thought it might be interesting to create another GridView extender &#8230; <a href="http://blog.ovesens.net/2007/09/creating-a-gridview-with-resizable-column-headers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>View the original post here:<br />
<a href="http://mattberseth.com/blog/2007/08/creating_a_gridview_with_resiz.html">http://mattberseth.com/blog/2007/08/creating_a_gridview_with_resiz.html</a></p>
<p>&#8212;</p>
<p>I was recently reading <a href="http://weblogs.asp.net/dwahlin/archive/2007/08/08/creating-an-asp-net-ajax-toolkit-extender-control.aspx"><span style="color: #b34c00;">Dan Wahlin&#8217;s</span></a> excellent &#8216;How To&#8217; for creating a GridView extender control.  While I was going through his code samples, I thought it might be interesting to create another GridView extender that allows you to resize the column widths of the GridView by clicking and dragging the header cell borders.  Before I went down the path of actually implementing the extender control, I wanted to get a feel for what the client side code for handling this might look like.  So I quick created a sample application where I added this functionality to the Google Analytics GridView I blogged about in an <a href="http://mattberseth.com/blog/2007/08/recreating_the_google_analytic.html"><span style="color: #b34c00;">earlier post</span></a>.</p>
<p><span style="color: #ff0000;">**</span> Because this sample is a proof of concept, I only tested in IE7.  If I move the code to an extender control I will go back and test it with other browsers.</p>
<p><a href="http://mattberseth2.com/resizeable_gridview_columns/" target="_blank"><span style="color: #b34c00;">Live Demo</span></a> (<em>Updated: 03-06-2011 &#8211; Link may not work</em>) | <a href="http://mattberseth2.com/downloads/resizeable_gridview_columns.zip"><span style="color: #b34c00;">Download</span></a></p>
<p>Before I get into the implementation details, here is a quick screen shot of the grid.  Unfortunately the mouse cursor didn&#8217;t come across in the screen shot, but when it is placed over the cell borders in the header row, it displays the east/west pointing arrow.</p>
<p><img src="http://mattberseth.com/WindowsLiveWriter/ResizableGridViewHeaderColumns_137A5/image%7B0%7D%5B1%5D.png" alt="" width="710" height="339" /></p>
<p>Adding this behavior to the existing GridView required implementing a handful of JavaScript functions.  My approach for implementing this features was to do the following:</p>
<ol>
<li>Handle each of the header cells&#8217;s mousemove events to determine when the user has the cursor placed roughly over the cell&#8217;s right hand border.  If a resize is already in processes then I use this event to determine what the new width of the column should be</li>
<li>Handle each of the header cell&#8217;s mousedown events to determine when the resizing begins</li>
<li>Handle the document&#8217;s mouseup event.  When this occurs I make sure that the resize has stopped</li>
<li>Handle the document&#8217;s selectstart event.  I cancel this event if a resize is currently in executing.  Doing this make&#8217;s sure that the header cell&#8217;s text isn&#8217;t highlighted when I am resizing the cell.  I learned this trick from the AjaxControlToolkit&#8217;s ResizeableControlExtender.  Here is a screen shot of what this would look like if you don&#8217;t cancel this event:</li>
</ol>
<p><img src="http://mattberseth.com/WindowsLiveWriter/ResizableGridViewHeaderColumns_137A5/image%7B0%7D%5B4%5D.png" alt="" width="184" height="88" align="left" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h4>pageLoad Event Handler</h4>
<p>First, I added the pageLoad JavaScript function to my page.  The ASP.NET AJAX framework will call this method for you so you will not have to worry about wiring it up.  I use this method to add event handlers to the mousemove and mousedown events for the table&#8217;s header cells.  Additionally I add handlers for the document level mouseup and selectstart events as follows &#8230;</p>
<pre class="csharpcode"><span class="rem">//  true when a header is currently being resized</span><span class="kwrd">var</span> _isResizing;<span class="rem">//  a reference to the header column that is being resized</span><span class="kwrd">var</span> _element;<span class="rem">//  an array of all of the tables header cells</span><span class="kwrd">var</span> _ths;<span class="kwrd">function</span> pageLoad(args){    <span class="rem">//  get all of the th elements from the gridview</span>    _ths = $get(<span class="str">'gvCustomers'</span>).getElementsByTagName(<span class="str">'TH'</span>);        <span class="rem">//  if the grid has at least one th element</span>    <span class="kwrd">if</span>(_ths.length &gt; 1){            <span class="kwrd">for</span>(i = 0; i &lt; _ths.length; i++){            <span class="rem">//  determine the widths</span>            _ths[i].style.width = Sys.UI.DomElement.getBounds(_ths[i]).width + <span class="str">'px'</span>;                    <span class="rem">//  attach the mousemove and mousedown events</span>            <span class="kwrd">if</span>(i &lt; _ths.length - 1){                $addHandler(_ths[i], <span class="str">'mousemove'</span>, _onMouseMove);                $addHandler(_ths[i], <span class="str">'mousedown'</span>, _onMouseDown);            }        }        <span class="rem">//  add a global mouseup handler            </span>        $addHandler(document, <span class="str">'mouseup'</span>, _onMouseUp);        <span class="rem">//  add a global selectstart handler</span>        $addHandler(document, <span class="str">'selectstart'</span>, _onSelectStart);    }       }</pre>
<h4>TH&#8217;s mousemove Event</h4>
<p>Next, I add logic to the mousemove event handler.  This event will fire everytime the mouse position changes while the cursor is over any of the header cells.  The code in this handler first checks to see if we are currently resizing a cell.  If we are, we do a little math to figure out what the new width of the column being resized needs to be.  If a resize is not currently taking place, then I check to see how close the mouse cursor is to the cells right hand border.  If it is within 2 pixels I display the east/west cursor so the user knows they can resize the cell.  Here is the JavaScript code for this handler &#8230;</p>
<pre class="csharpcode"><span class="kwrd">function</span> _onMouseMove(args){        <span class="kwrd">if</span>(_isResizing){                <span class="rem">//  determine the new width of the header</span>        <span class="kwrd">var</span> bounds = Sys.UI.DomElement.getBounds(_element);         <span class="kwrd">var</span> width = args.clientX - bounds.x;                <span class="rem">//  we set the minimum width to 1 px, so make</span>        <span class="rem">//  sure it is at least this before bothering to</span>        <span class="rem">//  calculate the new width</span>        <span class="kwrd">if</span>(width &gt; 1){                    <span class="rem">//  get the next th element so we can adjust its size as well</span>            <span class="kwrd">var</span> nextColumn = _element.nextSibling;            <span class="kwrd">var</span> nextColumnWidth;            <span class="kwrd">if</span>(width &lt; _toNumber(_element.style.width)){                <span class="rem">//  make the next column bigger</span>                nextColumnWidth = _toNumber(nextColumn.style.width) + _toNumber(_element.style.width) - width;            }            <span class="kwrd">else</span> <span class="kwrd">if</span>(width &gt; _toNumber(_element.style.width)){                <span class="rem">//  make the next column smaller</span>                nextColumnWidth = _toNumber(nextColumn.style.width) - (width - _toNumber(_element.style.width));            }                           <span class="rem">//  we also don't want to shrink this width to less than one pixel,</span>            <span class="rem">//  so make sure of this before resizing ...</span>            <span class="kwrd">if</span>(nextColumnWidth &gt; 1){                _element.style.width = width + <span class="str">'px'</span>;                nextColumn.style.width = nextColumnWidth + <span class="str">'px'</span>;            }        }    }       <span class="kwrd">else</span>{        <span class="rem">//  get the bounds of the element.  If the mouse cursor is within</span>        <span class="rem">//  2px of the border, display the e-cursor -&gt; cursor:e-resize</span>        <span class="kwrd">var</span> bounds = Sys.UI.DomElement.getBounds(args.target);        <span class="kwrd">if</span>(Math.abs((bounds.x + bounds.width) - (args.clientX)) &lt;= 2) {            args.target.style.cursor = <span class="str">'e-resize'</span>;        }          <span class="kwrd">else</span>{            args.target.style.cursor = <span class="str">''</span>;        }              }         }</pre>
<h4>TH&#8217;s mousedown Event</h4>
<p>The mousedown event handler if very simple.  If checks if the cursor is style is &#8216;e-resize&#8217;.  If so it sets the _isResizing bit to true so the other handlers know that a resize is currently taking place.  It also grabs the header cell that is being resized.  Here is the code &#8230;</p>
<pre class="csharpcode"><span class="kwrd">function</span> _onMouseDown(args){    <span class="rem">//  if the user clicks the mouse button while</span>    <span class="rem">//  the cursor is in the resize position, it means</span>    <span class="rem">//  they want to start resizing.  Set _isResizing to true</span>    <span class="rem">//  and grab the th element that is being resized</span>    <span class="kwrd">if</span>(args.target.style.cursor == <span class="str">'e-resize'</span>) {        _isResizing = <span class="kwrd">true</span>;        _element = args.target;                   }                    }</pre>
<h4>document&#8217;s mouseup Event</h4>
<p>Next, I added code for the mouseup event.  This is a handler is setup at the document level so no matter where the user lets go of the button this logic will be executed.  This handler does 2 things: resets the _isResizing and _element values back to there unitialized state and resets the header cells cursor style back to its initial state.  Here is the code for this &#8230;</p>
<pre class="csharpcode"><span class="kwrd">function</span> _onMouseUp(args){    <span class="rem">//  the user let go of the mouse - so</span>    <span class="rem">//  they are done resizing the header.  Reset</span>    <span class="rem">//  everything back</span>    <span class="kwrd">if</span>(_isResizing){                <span class="rem">//  set back to default values</span>        _isResizing = <span class="kwrd">false</span>;        _element = <span class="kwrd">null</span>;                <span class="rem">//  make sure the cursor is set back to default</span>        <span class="kwrd">for</span>(i = 0; i &lt; _ths.length; i++){               _ths[i].style.cursor = <span class="str">''</span>;        }    }}</pre>
<h4>document&#8217;s selectstart Event</h4>
<p>Finally, the last handler.  Like I mentioned earlier, I added this one to prevent the header cell&#8217;s text from highlighting as I am resizing the cells.  All this function does is cancel&#8217;s the event if a resize is currently executing.  Here is the code for this &#8230;</p>
<pre class="csharpcode"><span class="kwrd">function</span> _onSelectStart(args){    <span class="rem">// Don't allow selection during drag</span>    <span class="kwrd">if</span>(_isResizing){        args.preventDefault();        <span class="kwrd">return</span> <span class="kwrd">false</span>;    }}</pre>
<p>That&#8217;s it. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2007/09/creating-a-gridview-with-resizable-column-headers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ASP.NET Charting</title>
		<link>http://blog.ovesens.net/2007/09/asp-net-charting/</link>
		<comments>http://blog.ovesens.net/2007/09/asp-net-charting/#comments</comments>
		<pubDate>Wed, 19 Sep 2007 14:21:00 +0000</pubDate>
		<dc:creator>Mikkel Ovesen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[control]]></category>

		<guid isPermaLink="false">/post/2007/09/19/ASPNET-Charting.aspx</guid>
		<description><![CDATA[Dundas and other Chart controls are often very expensive, that makes them unattractive for small and lowbudget projects. Well, free charting controls do exist. NPlot is a free charting library for .NET (http://www.nplot.com/), WebChart is also free (http://www.carlosag.net/Tools/WebChart/Default.aspx) The guys &#8230; <a href="http://blog.ovesens.net/2007/09/asp-net-charting/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>
Dundas and other Chart controls are often very expensive, that makes them unattractive for small and lowbudget projects.
</p>
<p>
Well, free charting controls do exist. NPlot is a free charting library for .NET (<a href="http://www.nplot.com/">http://www.nplot.com/</a>), WebChart is also free (<a href="http://www.carlosag.net/Tools/WebChart/Default.aspx">http://www.carlosag.net/Tools/WebChart/Default.aspx</a>)
</p>
<p>
The guys from rolla have written an article here about it:
</p>
<p>
<a href="http://aspnet.4guysfromrolla.com/articles/072507-1.aspx">http://aspnet.4guysfromrolla.com/articles/072507-1.aspx</a>
</p>
<p>
NPlot example:
</p>
<p>
<img src="http://netcontrols.org/nplot/wiki/Clients/Main/chart2.png" alt="" width="615" height="361" />
</p>
<p>
WebChart
</p>
<p>
<img src="http://www.carlosag.net/images/chartSample.Png" alt="Chart Sample" width="500" height="350" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ovesens.net/2007/09/asp-net-charting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

