<?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; masterpages</title>
	<atom:link href="http://jesal.us/tag/masterpages/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>
	</channel>
</rss>
