<?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; usercontrols</title>
	<atom:link href="http://jesal.us/tag/usercontrols/feed/" rel="self" type="application/rss+xml" />
	<link>http://jesal.us</link>
	<description></description>
	<lastBuildDate>Thu, 14 Jul 2011 18:51:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>How To Load &amp; Reference An Usercontrol From Code Behind</title>
		<link>http://jesal.us/2008/09/how-to-load-reference-a-user-control-from-code-behind/</link>
		<comments>http://jesal.us/2008/09/how-to-load-reference-a-user-control-from-code-behind/#comments</comments>
		<pubDate>Mon, 01 Sep 2008 21:56:30 +0000</pubDate>
		<dc:creator>J</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[usercontrols]]></category>

		<guid isPermaLink="false">http://jesal.us/blog/?p=93</guid>
		<description><![CDATA[First lets create a sample user control called MyControl for demonstration purposes public partial class _Controls_MyControl : System.Web.UI.UserControl { private string _myProperty; public string MyProperty { get { return _myProperty; } set { _myProperty = value; } } protected void Page_Load(object sender, EventArgs e) { } } Now register this control in the web.config &#60;pages&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>First lets create a sample user control called MyControl for demonstration purposes</p>
<pre name="code" class="csharp:nogutter">
public partial class _Controls_MyControl : System.Web.UI.UserControl
{
    private string _myProperty;

    public string MyProperty
    {
        get { return _myProperty; }
        set { _myProperty = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }
}
</pre>
<p>Now register this control in the web.config</p>
<pre name="code" class="xml:nogutter">
&lt;pages&gt;
  &lt;controls&gt;
    &lt;add tagPrefix="uc" tagName="MyControl" src="~/_Controls/MyControl.ascx"/&gt;
  &lt;/controls&gt;
&lt;/pages&gt;
</pre>
<p>Now this is the most important part, you have to reference your user control in the .aspx page to be able to access its partial class members -</p>
<pre name="code" class="xml:nogutter">
<%@ Reference Control="~/_Controls/MyControl.ascx" %>
</pre>
<p>Now finally lets instantiate and load the control from the code behind&#8230;</p>
<pre name="code" class="csharp:nogutter">
_Controls_MyControl myControl = (_Controls_MyControl)LoadControl("~/_Controls/MyControl.ascx");
myControl.MyProperty = "Hello World!!";
Page.Controls.Add(myControl);
</pre>
<p>That&#8217;s it</p>
]]></content:encoded>
			<wfw:commentRss>http://jesal.us/2008/09/how-to-load-reference-a-user-control-from-code-behind/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

