<?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>jesal gadhia &#187; errors</title>
	<atom:link href="http://jesal.us/tag/errors/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Fri, 19 Mar 2010 05:32:28 +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>Code Blocks Inside Master Pages</title>
		<link>http://jesal.us/2008/09/code-blocks-inside-master-pages/</link>
		<comments>http://jesal.us/2008/09/code-blocks-inside-master-pages/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 18:22:49 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[masterpages]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=96</guid>
		<description><![CDATA[Some time ago I kept getting this error in one of the projects I was working on:
The Controls collection cannot be modified because the control contains code blocks (i.e. ).
I spent quite some time trying to figure it out. Finally after hours of searching I found out that Code Blocks Inside Master Pages Cause Trouble.
I [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I kept getting this error in one of the projects I was working on:</p>
<p><strong>The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>).</strong></p>
<p>I spent quite some time trying to figure it out. Finally after hours of searching I found out that <a href="http://aspnetresources.com/blog/code_blocks_inside_master_pages_cause_trouble.aspx" target="_blank">Code Blocks Inside Master Pages Cause Trouble</a>.</p>
<p>I was using code blocks inside the head tag of all the MasterPages to resolve paths at runtime:</p>
<pre>
&lt;link rel="stylesheet" href="&lt;%= ResolveUrl("~/myStyleSheet.css") %&gt;" type="text/css" /&gt;
&lt;script type="text/javascript" src="&lt;%= ResolveUrl("~/myJavaScript.js") %&gt;"&gt;&lt;/script&gt;
</pre>
<p>Fortunately <a href="http://aspnetresources.com/blog/code_blocks_inside_master_pages_cause_trouble.aspx">Milan Negovan</a> proposed a quick workaround which saved a lot of time.</p>
<p>Basically, the workaround is to change the code blocks to data binding expressions (<%# ... %>). </p>
<pre>
&lt;link rel="stylesheet" href="&lt;%# ResolveUrl("~/myStyleSheet.css") %&gt;" type="text/css" /&gt;
&lt;script type="text/javascript" src="&lt;%# ResolveUrl("~/myJavaScript.js") %&gt;"&gt;&lt;/script&gt;
</pre>
<p>and adding this to the master page code behind:</p>
<pre name="code" class="csharp:nogutter">
protected override void OnLoad (EventArgs e)
{
  base.OnLoad (e);
  Page.Header.DataBind ();
}
</pre>
<p>Since HtmlHead ultimately derives from Control and everything that derives from Control has a DataBind() method, adding that one line above would force the header to resolve data binding expressions.</p>
<p>Thats it, that does the trick!</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/09/code-blocks-inside-master-pages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Mysterious &#8220;Invalid Parameter Used&#8221; Error</title>
		<link>http://jesal.us/2008/03/the-mysterious-invalid-parameter-used-error/</link>
		<comments>http://jesal.us/2008/03/the-mysterious-invalid-parameter-used-error/#comments</comments>
		<pubDate>Sat, 29 Mar 2008 07:37:47 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[errors]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/2008/03/29/the-mysterious-invalid-parameter-used-error/</guid>
		<description><![CDATA[Recently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error &#8211; &#8220;Invalid Parameter Used&#8221; &#8211; whenever I tried [...]]]></description>
			<content:encoded><![CDATA[<p>Recently I was trying to write a little C# function for cropping images. I expected it to be a quick 5 minute task but I ended up spending a huge amount of time getting it to work correctly. I kept getting a very stubborn and mysterious error &#8211; &#8220;Invalid Parameter Used&#8221; &#8211; whenever I tried to save my newly cropped image by doing bitmap.Save(). I tried various suggestions I found on forums and blogs to no avail.</p>
<p>Finally I figured out what the problem was. I was encapulatning the Bitmap and Graphics objects inside a &#8220;using&#8221; statement. So the Bitmap object was being prematurely disposed before I returned it back to the caller.</p>
<p>So in the end my solution looked like this. I just god rid of the &#8220;usings&#8221;.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<pre class="csharpcode"><span class="kwrd">public</span> Bitmap CropImage(Image image, Rectangle cropRect)
{
    Bitmap bitmap = <span class="kwrd">new</span> Bitmap(cropRect.Width, cropRect.Height, PixelFormat.Format24bppRgb);
    bitmap.SetResolution(image.HorizontalResolution, image.VerticalResolution);
    Graphics graphics = Graphics.FromImage(bitmap);
    graphics.DrawImage(image, 0, 0, cropRect, GraphicsUnit.Pixel);
    <span class="kwrd">return</span> bitmap;
}</pre>
<p>Usage -<br />
<span class="csharpcode"><br />
Bitmap croppedBmp = CropImage(<span class="str">&#8220;~/uploads/test.jpg&#8221;</span>, <span class="kwrd">new</span> Rectangle(x, y, width, height));<br />
croppedBmp.Save();</span></p>
<p>Moral of the story: If you are getting this error while calling Bitmap.Save() then make sure you are not disposing your Bitmap object prematurely. Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/03/the-mysterious-invalid-parameter-used-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
