<?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: ASP.Net Dynamic Controls (Part 3)</title>
	<atom:link href="http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/</link>
	<description>Discussion on Development in Several Different Flavours</description>
	<lastBuildDate>Fri, 06 Jan 2012 16:25:42 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Pogi</title>
		<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/comment-page-1/#comment-65</link>
		<dc:creator>Pogi</dc:creator>
		<pubDate>Wed, 07 Nov 2007 05:02:55 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2006/12/23/aspnet-dynamic-controls-part-3/#comment-65</guid>
		<description>c#
1-recreate the controls in page load with the same name
2- use  Findcontrol. ie  ct1 =  FindControl(&quot;control_name1&quot;)
3- ct1 now has all the attributes and Values after postback.</description>
		<content:encoded><![CDATA[<p>c#<br />
1-recreate the controls in page load with the same name<br />
2- use  Findcontrol. ie  ct1 =  FindControl(&#8220;control_name1&#8243;)<br />
3- ct1 now has all the attributes and Values after postback.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam</title>
		<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/comment-page-1/#comment-64</link>
		<dc:creator>Adam</dc:creator>
		<pubDate>Wed, 24 Oct 2007 15:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2006/12/23/aspnet-dynamic-controls-part-3/#comment-64</guid>
		<description>After you postback the page you can access the controls you created using Request.Form(&quot;control_name&quot;)

Where control_name is the ID you gave the control when you created it. Hope that helps.</description>
		<content:encoded><![CDATA[<p>After you postback the page you can access the controls you created using Request.Form(&#8220;control_name&#8221;)</p>
<p>Where control_name is the ID you gave the control when you created it. Hope that helps.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nuno</title>
		<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/comment-page-1/#comment-63</link>
		<dc:creator>Nuno</dc:creator>
		<pubDate>Wed, 24 Oct 2007 14:48:47 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2006/12/23/aspnet-dynamic-controls-part-3/#comment-63</guid>
		<description>Hi i was reading your article, but i&#039;m having some problems of gettign the values of the dymanic controls that i created.

can you help me finish my work, please?</description>
		<content:encoded><![CDATA[<p>Hi i was reading your article, but i&#8217;m having some problems of gettign the values of the dymanic controls that i created.</p>
<p>can you help me finish my work, please?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Slava</title>
		<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/comment-page-1/#comment-62</link>
		<dc:creator>Slava</dc:creator>
		<pubDate>Thu, 10 May 2007 13:47:11 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2006/12/23/aspnet-dynamic-controls-part-3/#comment-62</guid>
		<description>That&#039;s nice. What about the following scenario: I&#039;m loading controls that implement the same interface - GetFieldValues and SetFieldValues methods. I&#039;m loading the first control, call SetFieldValues on it and then press &quot;Next&quot;, at this moment I want to call GetFieldValues and load the next control and so on. But it doesnt work just because the controls are dynamically loaded:

&lt;pre class=&quot;brush: csharp&quot;&gt;protected void Page_Init(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session[&quot;CurrentControl&quot;] = Stub.GetNextControlUrl();
            Control currentControl =

(Control)LoadControl((string)Session[&quot;CurrentControl&quot;]);
            PlaceHolder1.Controls.Add(currentControl);
            SetFields();
        }
        else
        {
            Control currentControl =

(Control)LoadControl((string)Session[&quot;CurrentControl&quot;]);
            PlaceHolder1.Controls.Add(currentControl);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            GetFields();

            Session[&quot;CurrentControl&quot;] =

Stub.GetNextControlUrl();
            Control currentControl =

(Control)LoadControl((string)Session[&quot;CurrentControl&quot;]);
            PlaceHolder1.Controls.Clear();
            PlaceHolder1.Controls.Add(currentControl);

            SetFields();
        }
    }
&lt;/pre&gt;

SetFields and GetFields just call a method on the controls inside PlaceHolder1 to retreive their field values. The problem is that I want the content of the controls to be retreived calling a method of the interface. Does anyone know how to solve this?</description>
		<content:encoded><![CDATA[<p>That&#8217;s nice. What about the following scenario: I&#8217;m loading controls that implement the same interface &#8211; GetFieldValues and SetFieldValues methods. I&#8217;m loading the first control, call SetFieldValues on it and then press &#8220;Next&#8221;, at this moment I want to call GetFieldValues and load the next control and so on. But it doesnt work just because the controls are dynamically loaded:</p>
<pre class="brush: csharp">protected void Page_Init(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Session["CurrentControl"] = Stub.GetNextControlUrl();
            Control currentControl =

(Control)LoadControl((string)Session["CurrentControl"]);
            PlaceHolder1.Controls.Add(currentControl);
            SetFields();
        }
        else
        {
            Control currentControl =

(Control)LoadControl((string)Session["CurrentControl"]);
            PlaceHolder1.Controls.Add(currentControl);
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack)
        {
            GetFields();

            Session["CurrentControl"] =

Stub.GetNextControlUrl();
            Control currentControl =

(Control)LoadControl((string)Session["CurrentControl"]);
            PlaceHolder1.Controls.Clear();
            PlaceHolder1.Controls.Add(currentControl);

            SetFields();
        }
    }
</pre>
<p>SetFields and GetFields just call a method on the controls inside PlaceHolder1 to retreive their field values. The problem is that I want the content of the controls to be retreived calling a method of the interface. Does anyone know how to solve this?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: sturla</title>
		<link>http://devsushi.com/2006/12/23/aspnet-dynamic-controls-part-3/comment-page-1/#comment-61</link>
		<dc:creator>sturla</dc:creator>
		<pubDate>Thu, 08 Mar 2007 16:37:55 +0000</pubDate>
		<guid isPermaLink="false">http://adamhewgill.com/devsushi/2006/12/23/aspnet-dynamic-controls-part-3/#comment-61</guid>
		<description>what about linkbutton? How can you verify that a linkbutton was clicked?


I&#039;ve solved the problem using code for coded webcontrols (not ascx and aspx) but cs class inhereting from System.Web.UI.WebControls.WebControl. The solution is to draw the content twice in different places of the lifespan. My experience is that i then can change the content of the page in the event and not get the &quot;lagg&quot; effect (event triggering one postback too late).

This is how i draw the dynamic content (nomatter what it is in webcontrols):


&lt;pre class=&quot;brush: csharp&quot;&gt;protected override void OnPreRender(EventArgs e)
{
	// Workaround to get events on buttons to work.
	// Check if this is the correct solution
	base.OnPreRender (e);
	if(this.Content != null)
	{
		this.Controls.Clear();
		main = this.DrawTable();
		this.Controls.Add(main);
	}
}

protected override void CreateChildControls()
{
	base.CreateChildControls ();
	if(this.Content!= null)
	{
		main = this.DrawTable();
		this.Controls.Add(main);
	}
}
&lt;/pre&gt;

Notice that the above actually works for aspx and ascx files too, but in an inconsistent matter. Can someone please explain to me why this works, since the solution was a aquired by trial and error.

One last thing. Always remember to give the controls and id.

Implementing ,System.Web.UI.INamingContainer seems to work good for webcontrols. Somehow this fails in usercontrols (ascx), but simply setting a unique id works.</description>
		<content:encoded><![CDATA[<p>what about linkbutton? How can you verify that a linkbutton was clicked?</p>
<p>I&#8217;ve solved the problem using code for coded webcontrols (not ascx and aspx) but cs class inhereting from System.Web.UI.WebControls.WebControl. The solution is to draw the content twice in different places of the lifespan. My experience is that i then can change the content of the page in the event and not get the &#8220;lagg&#8221; effect (event triggering one postback too late).</p>
<p>This is how i draw the dynamic content (nomatter what it is in webcontrols):</p>
<pre class="brush: csharp">protected override void OnPreRender(EventArgs e)
{
	// Workaround to get events on buttons to work.
	// Check if this is the correct solution
	base.OnPreRender (e);
	if(this.Content != null)
	{
		this.Controls.Clear();
		main = this.DrawTable();
		this.Controls.Add(main);
	}
}

protected override void CreateChildControls()
{
	base.CreateChildControls ();
	if(this.Content!= null)
	{
		main = this.DrawTable();
		this.Controls.Add(main);
	}
}
</pre>
<p>Notice that the above actually works for aspx and ascx files too, but in an inconsistent matter. Can someone please explain to me why this works, since the solution was a aquired by trial and error.</p>
<p>One last thing. Always remember to give the controls and id.</p>
<p>Implementing ,System.Web.UI.INamingContainer seems to work good for webcontrols. Somehow this fails in usercontrols (ascx), but simply setting a unique id works.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

