Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Controls From a Page Object
    primarykey
    data
    text
    <p>I am new to .Net platform and I am stuck in retrieving controls from .aspx pages since two days.</p> <p>I am trying to get all the <code>controls</code> from all the <code>.aspx</code> pages in my website. So for that I create the object of the Page from the string of class name which I get from my database. I have already stored the <code>class names</code> of .aspx.cs files in database</p> <p>The code in C# is:</p> <pre><code>Page obj = (Page)Activator.CreateInstance(null, string ClassName).Unwrap(); </code></pre> <p>The string <code>"ClassName"</code> is taken from the database.</p> <p>Now during Debug time I can see that there are <code>controls</code> in the <code>obj</code> but I get <code>0</code> in <code>controls.count</code>. I guess this is because the controls are still <code>not initialized</code>.</p> <p><strong><em>Image 1 during debug time</em></strong><img src="https://i.stack.imgur.com/Av6KK.jpg" alt="Image 1 during debug time">:</p> <p><strong><em>Image 2 during debug time showing my controls</em></strong><img src="https://i.stack.imgur.com/58NaA.jpg" alt="Image 2 during debug time showing my controls"></p> <p>My code looks like this.</p> <pre><code>Page obj = (Page)Activator.CreateInstance(null, string ClassName).Unwrap() List&lt;string[]&gt; fieldsNotInDB = GetControlCollections(obj) </code></pre> <p>This is my <code>function</code> to get all the <code>controls</code> from the <code>Page obj</code></p> <pre><code>public List&lt;string[]&gt; GetControlCollections(Page p) { List&lt;string[]&gt; controlList = new List&lt;string[]&gt;(); IterateControls(p.Controls, controlList); return controlList; } public void IterateControls(System.Web.UI.ControlCollection page, List&lt;string[]&gt; controlList) { foreach (System.Web.UI.Control c in page) { if (c.ID != null) { string []s=new string[2]; s[0]=c.ID; s[1]=c.GetType().ToString(); controlList.Add(s); } if (c.HasControls()) { IterateControls(c.Controls, controlList); } } } </code></pre> <p>How do I get the <code>Controls</code> from my <code>obj</code>?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload