<?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>Justin Carmony &#187; Server Controls</title>
	<atom:link href="http://www.justincarmony.com/blog/tag/server-controls/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justincarmony.com/blog</link>
	<description>Web Designer &#38; Software Engineer</description>
	<lastBuildDate>Sun, 13 May 2012 20:36:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Page.FindControl() Returning Null Issues and Solutions Within Another Control</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/</link>
		<comments>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comments</comments>
		<pubDate>Tue, 12 Feb 2008 18:41:51 +0000</pubDate>
		<dc:creator>Justin Carmony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP .NET]]></category>
		<category><![CDATA[Server Controls]]></category>

		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/</guid>
		<description><![CDATA[Alright, I&#8217;m going to have a lot of blog posts over the next few days going over my wonderful expereinces learning how to create advanced server controls, and just how hard it is to find good information on the subject. But the problem I ran into today was having Page.FindControl() not work as expected. Problem ...
Related posts:<ol>
<li><a href='http://www.justincarmony.com/blog/2008/01/07/asp-net-20-gridviews-hyperlinkfield-and-javascript/' rel='bookmark' title='ASP .NET 2.0, GridViews, HyperLinkField, and JavaScript'>ASP .NET 2.0, GridViews, HyperLinkField, and JavaScript</a> <small>I&#8217;ve found some interesting notes on ASP .NET&#8217;s GridView, it&#8217;s...</small></li>
<li><a href='http://www.justincarmony.com/blog/2008/01/22/asp-net-gridview-access-to-data-in-code/' rel='bookmark' title='ASP .NET GridView Access to Data In Code'>ASP .NET GridView Access to Data In Code</a> <small>There are situations where you want to gain access to...</small></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Alright, I&#8217;m going to have a lot of blog posts over the next few days going over my wonderful expereinces learning how to create advanced server controls, and just how hard it is to find good information on the subject.  But the problem I ran into today was having Page.FindControl() not work as expected.</p>
<h3>Problem</h3>
<p>Page.FindControl() can be misleading. A developer without understanding the situation could assume FindControl() will return a control found within that page. <strong><font color="#ff0000"><u><em>This is completely wrong.</em></u></font> </strong>The reason this does not work is because Page does not have its own FindControl() function. It actually <em><strong>inherits</strong> </em>this from Control, because Page inherits control. So FindControl() is really more like a FindChildrenControls(), and it is <em><strong>not</strong></em> recursive.</p>
<h3>Example</h3>
<p>I have some code that does a Page.FindControl() for a GridView. However, later I <em><strong>move</strong></em> the GridView into an UpdatePanel to add ajax enabled stuff. All of a sudden my Page.FindControl() doesn&#8217;t work. The reason? Because my GridView is no longer a direct child of the Page and it is now a child of the UpdatePanel. So instead of being Page -&gt; GridView it is Page -&gt; UpdatePanel -&gt; GridView.</p>
<h3>Solution</h3>
<p><span id="more-17"></span>I found a <a href="http://www.codinghorror.com/blog/archives/000307.html" title="Coding Horror: Recursive Page.FindControl" target="_blank">blog post</a> for a recursive post.  Here is the code:</p>
<pre class="brush: csharp; title: ; notranslate">
private Control FindControlRecursive(Control root, string id)
{
if (root.ID == id)
{
return root;
}

foreach (Control c in root.Controls)
{
Control t = FindControlRecursive(c, id);
if (t != null)
{
return t;
}
}

return null;
}
</pre>
<p>Related posts:<ol>
<li><a href='http://www.justincarmony.com/blog/2008/01/07/asp-net-20-gridviews-hyperlinkfield-and-javascript/' rel='bookmark' title='ASP .NET 2.0, GridViews, HyperLinkField, and JavaScript'>ASP .NET 2.0, GridViews, HyperLinkField, and JavaScript</a> <small>I&#8217;ve found some interesting notes on ASP .NET&#8217;s GridView, it&#8217;s...</small></li>
<li><a href='http://www.justincarmony.com/blog/2008/01/22/asp-net-gridview-access-to-data-in-code/' rel='bookmark' title='ASP .NET GridView Access to Data In Code'>ASP .NET GridView Access to Data In Code</a> <small>There are situations where you want to gain access to...</small></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 19/31 queries in 0.010 seconds using memcached
Content Delivery Network via Rackspace Cloud Files: c747925.r25.cf2.rackcdn.com

Served from: www.justincarmony.com @ 2012-05-21 10:19:13 -->
