Using PostBackUrl, Getting PreviousPage.Control()
<p>I'm using PostBackUrl to post my control from a "firstwebpage.aspx" to a "secondwebpage.aspx" so that I would be able to generate some configuration files.</p>

<p>I do understand that I can make use of <strong>PreviousPage.FindControl("myControlId")</strong> method in my secondwebpage.aspx to get my control from "firstwebpage.aspx"and hence grab my data and it worked.</p>

<p>However, it seems that this method does not work on controls which I generated programmically during runtime while populating them in a table in my firstwebpage.aspx.</p>

<p>I also tried using this function <strong>Response.Write("--" + Request["TextBox1"].ToString() + "--");</strong>
And although this statement do printout the text in the textfield on TextBox1, it only return me the string value of textbox1. I am unable to cast it to a textbox control in the following format too</p>

<p><strong>TextBox temptextBox = (TextBox)Request["TextBox1"];</strong></p>

<p>My question is, how can I actually access the control which i generated <strong>programmically</strong> in "firstwebpage.aspx" on "secondwebpage.aspx"?</p>

<p>Please advice! 
thanks alot!</p>

<p>//my panel and button in aspx</p>

<pre><code>&lt;asp:Panel ID="Panel2" runat="server"&gt;&lt;/asp:Panel&gt;

&lt;asp:Button ID="Button1" runat="server" Text="Generate Xml" PostBackUrl="~/WebForm2.aspx" onclick="Button1_Click" /&gt;
</code></pre>

<p>//this is my function to insert a line into the panel</p>

<pre><code> public void createfilerow(string b, string path, bool x86check, bool x86enable, bool x64check, bool x64enable)
        {
            Label blank4 = new Label();
            blank4.ID = "blank4";
            blank4.Text = "";
            Panel2.Controls.Add(blank4);

            CheckBox c = new CheckBox();
            c.Text = b.Replace(path, "");
            c.Checked = true;
            c.ID = "1a";
            Panel2.Controls.Add(c);

            CheckBox d = new CheckBox();
            d.Checked = x86check;
            d.Enabled = x86enable;
            d.ID = "1b";
            Panel2.Controls.Add(d);

            CheckBox e = new CheckBox();            
            e.Checked = x64check;
            e.Enabled = x64enable;
            e.ID = "1c";
            Panel2.Controls.Add(e);
    }

//my virtual path in WebForm2.aspx

&lt;%@ PreviousPageType VirtualPath="~/WebForm1.aspx"  %&gt;
</code></pre>

<p>//my pageload handler</p>

<pre><code>protected void Page_Load(object sender, EventArgs e)
{  
    if (PreviousPage != null)
    {
        CheckBox tempCheckbox = (CheckBox)Page.PreviousPage.FindControl("1a");
        Button1.Text = tempCheckbox.Text;
    }         
}
</code></pre>

<p>//handler which will populate the panel upon clicking</p>

<pre><code>protected void Button7_Click(object sender, EventArgs e)
        {
            //get foldername 

            if (!Directory.Exists(@"myfilepath" + TextBox2.Text))
            {
                //folder does not exist
                //do required actions
                return;
            }
            string[] x86files = null;
            string[] x64files = null;
            string[] x86filespath = null;
            string[] x64filespath = null;
            ArrayList common = new ArrayList();
            if (Directory.Exists(@"myfilepath" + TextBox2.Text + "\\x86"))
                x86files = Directory.GetFileSystemEntries("myfilepath" + TextBox2.Text + "\\x86");
            if (Directory.Exists(@"myfilepath" + TextBox2.Text + "\\x64"))
                x64files = Directory.GetFileSystemEntries("myfilepath" + TextBox2.Text + "\\x64");

            //some codes to convert x64files and x86files to string[]

            //The header for Panel, 4 column
            Label FL = new Label();
            FL.ID = "flavourid";
            FL.Text = "Flavour";
            Panel2.Controls.Add(FL);

            Label filetext = new Label();
            filetext.ID = "filenamelabel";
            filetext.Text = "File(s)";
            Panel2.Controls.Add(filetext);

            Label label86 = new Label();
            label86.ID = "label86";
            label86.Text = "x86";
            Panel2.Controls.Add(label86);

            Label label64 = new Label();
            label64.ID = "label64";
            label64.Text = "x64";
            Panel2.Controls.Add(label64);


            //a for loop determine number of times codes have to be run
            for (int a = 0; a &lt; num; a++)
            {
                ArrayList location = new ArrayList();
                if (//this iteration had to be run)
                {
                    string path = null;
                    switch (//id of this iteration)
                    {
                     case id:
                     path = some network address
                    }

                    //check the current version of iternation
                    string version = //version type;
                    //get the platform of the version
                    string platform = //platform

                    if (curent version = certain type)
                    {   
                        //do what is required.
                        //build a list
                    }
                    else
                    {
                        //normal routine
                        //do what is required
                        //build a list
                    }

                    //populating the panel with data from list

                        createflavourheader(a);
                        //create dynamic checkboxes according to the list

                     foreach(string s in list)
                     //createrow parameter is by version type and platform
                             createfilerow(readin, path, true, true, false, false);

                    }
                }
            }
            form1.Controls.Add(Panel2);
        }    
</code></pre>

<p>Sorry can't show you the full code as it is long and I believe it should be confidential even though i wrote them all</p>
