<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Page.FindControl() Returning Null Issues and Solutions Within Another Control</title>
	<atom:link href="http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/</link>
	<description>Web Designer &#38; Software Engineer</description>
	<lastBuildDate>Tue, 15 May 2012 02:22:31 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
	<item>
		<title>By: Yusuf Irzan</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-49713</link>
		<dc:creator>Yusuf Irzan</dc:creator>
		<pubDate>Thu, 03 May 2012 07:17:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-49713</guid>
		<description>Sometimes developer must understand where to place this code.
If you&#039;re code in user control, you should use Parent.FindControl.
I found this solution in my application.</description>
		<content:encoded><![CDATA[<p>Sometimes developer must understand where to place this code.<br />
If you&#8217;re code in user control, you should use Parent.FindControl.<br />
I found this solution in my application.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: peetinun</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-48739</link>
		<dc:creator>peetinun</dc:creator>
		<pubDate>Fri, 07 Oct 2011 05:22:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-48739</guid>
		<description>This article is very nice.
Thank you very much.</description>
		<content:encoded><![CDATA[<p>This article is very nice.<br />
Thank you very much.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dotNetFollower</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-48725</link>
		<dc:creator>dotNetFollower</dc:creator>
		<pubDate>Fri, 30 Sep 2011 04:59:24 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-48725</guid>
		<description>Nice post! My own FindControlRecursive helped me out many times. Especially, when I deal with MasterPages. For example, one of such usage is shown in my post here – &lt;a href=&quot;http://dotnetfollower.com/wordpress/2010/12/sharepoint-add-onchange-attribute-to-dropdownchoicefield/&quot; rel=&quot;nofollow&quot;&gt;http://dotnetfollower.com/wordpress/2010/12/sharepoint-add-onchange-attribute-to-dropdownchoicefield/&lt;/a&gt;.
Thank you!</description>
		<content:encoded><![CDATA[<p>Nice post! My own FindControlRecursive helped me out many times. Especially, when I deal with MasterPages. For example, one of such usage is shown in my post here – <a href="http://dotnetfollower.com/wordpress/2010/12/sharepoint-add-onchange-attribute-to-dropdownchoicefield/" rel="nofollow">http://dotnetfollower.com/wordpress/2010/12/sharepoint-add-onchange-attribute-to-dropdownchoicefield/</a>.<br />
Thank you!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Trikks</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-48622</link>
		<dc:creator>Trikks</dc:creator>
		<pubDate>Thu, 30 Jun 2011 08:54:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-48622</guid>
		<description>Hi, thanks!

Improved it a bit

private Control FindControlRecursive(string id)
{
    Page page = HttpContext.Current.Handler as Page;
    return FindControlRecursive(page, id);
}

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;
}


Call it like this


Literal debug = (Literal)FindControlRecursive(&quot;debug&quot;);
debug.Text = &quot;asdasd&quot;;


Nice, thanks again</description>
		<content:encoded><![CDATA[<p>Hi, thanks!</p>
<p>Improved it a bit</p>
<p>private Control FindControlRecursive(string id)<br />
{<br />
    Page page = HttpContext.Current.Handler as Page;<br />
    return FindControlRecursive(page, id);<br />
}</p>
<p>private Control FindControlRecursive(Control root, string id)<br />
{<br />
    if (root.ID == id)<br />
    {<br />
        return root;<br />
    }</p>
<p>    foreach (Control c in root.Controls)<br />
    {<br />
        Control t = FindControlRecursive(c, id);<br />
        if (t != null)<br />
        {<br />
            return t;<br />
        }<br />
    }</p>
<p>    return null;<br />
}</p>
<p>Call it like this</p>
<p>Literal debug = (Literal)FindControlRecursive(&#8220;debug&#8221;);<br />
debug.Text = &#8220;asdasd&#8221;;</p>
<p>Nice, thanks again</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: bugs</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-48538</link>
		<dc:creator>bugs</dc:creator>
		<pubDate>Wed, 13 Apr 2011 19:45:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-48538</guid>
		<description>Hi, i rarely subscribe to all possible web site in the world, but i have donne it with yours just to thanks you.

I regularly got a lot of problem to correctly findcontrol for a lot of situation of control inside another control, and so on...

for now it is so easy with the function you write above

thanks a lot again :)</description>
		<content:encoded><![CDATA[<p>Hi, i rarely subscribe to all possible web site in the world, but i have donne it with yours just to thanks you.</p>
<p>I regularly got a lot of problem to correctly findcontrol for a lot of situation of control inside another control, and so on&#8230;</p>
<p>for now it is so easy with the function you write above</p>
<p>thanks a lot again <img src='http://c747925.r25.cf2.rackcdn.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wheels</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-48269</link>
		<dc:creator>Wheels</dc:creator>
		<pubDate>Fri, 11 Mar 2011 19:00:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-48269</guid>
		<description>Hi Tom. I replaced Page.FindControl() with NamingContainer.FindControl(), but I am getting a 
object Reference not set to an instance of an object error. 

My code is as follows:

string ctrlStr = String.Empty;
                Control c = null;
                foreach (string ctl in HttpContext.Current.Request.Form)
                {
                    // handle ImageButton controls ...
                    if (ctl.EndsWith(&quot;.x&quot;) &#124;&#124; ctl.EndsWith(&quot;.y&quot;))
                    {
                        ctrlStr = ctl.Substring(0, ctl.Length - 2).Replace(&quot;$&quot;, &quot;_&quot;);
                        //c = page.FindControl(ctrlStr);
                        c = page.NamingContainer.FindControl(ctrlStr);
                    }

WHEELS</description>
		<content:encoded><![CDATA[<p>Hi Tom. I replaced Page.FindControl() with NamingContainer.FindControl(), but I am getting a<br />
object Reference not set to an instance of an object error. </p>
<p>My code is as follows:</p>
<p>string ctrlStr = String.Empty;<br />
                Control c = null;<br />
                foreach (string ctl in HttpContext.Current.Request.Form)<br />
                {<br />
                    // handle ImageButton controls &#8230;<br />
                    if (ctl.EndsWith(&#8220;.x&#8221;) || ctl.EndsWith(&#8220;.y&#8221;))<br />
                    {<br />
                        ctrlStr = ctl.Substring(0, ctl.Length &#8211; 2).Replace(&#8220;$&#8221;, &#8220;_&#8221;);<br />
                        //c = page.FindControl(ctrlStr);<br />
                        c = page.NamingContainer.FindControl(ctrlStr);<br />
                    }</p>
<p>WHEELS</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Fafa</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-47978</link>
		<dc:creator>Fafa</dc:creator>
		<pubDate>Fri, 25 Feb 2011 15:47:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-47978</guid>
		<description>Yes, many thanks !</description>
		<content:encoded><![CDATA[<p>Yes, many thanks !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DidilWydadi</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-46758</link>
		<dc:creator>DidilWydadi</dc:creator>
		<pubDate>Thu, 23 Dec 2010 17:25:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-46758</guid>
		<description>Thank you very much!!!</description>
		<content:encoded><![CDATA[<p>Thank you very much!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-46580</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Fri, 19 Nov 2010 09:47:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-46580</guid>
		<description>Replace Page.FindControl() to NamingContainer.FindControl()</description>
		<content:encoded><![CDATA[<p>Replace Page.FindControl() to NamingContainer.FindControl()</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/comment-page-1/#comment-46268</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Wed, 20 Oct 2010 15:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.justincarmony.com/blog/2008/02/12/pagefindcontrol-returning-null-issues-and-solutions-within-another-control/#comment-46268</guid>
		<description>Thank you very much!!!  What a life saver.</description>
		<content:encoded><![CDATA[<p>Thank you very much!!!  What a life saver.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 17/27 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-17 21:42:42 -->
