1
Answer

finding custom controls in codebehind.

Lee

Lee

19y
2.1k
1
I have written a webcustomcontrol (NOT ascx). 
I have 10 on a web page and want to find them in the code behind.

I have tried using foreach, but I am not sure what collection to search in. 

Does anyone know the answer to this question? Is it possible?

Thanks in advance,

Lee
Answers (1)
0
Lee

Lee

NA 27 0 19y
More info:

I have found out how to do it, but I have a problem

[CODE]

Type t;

foreach (Control oPart in this.Controls)                // Loop through the controls on the page.

{

t = typeof(SMDCMS.WebPart);

if (t.FullName.IndexOf("WebPart")>0)

{

PropertyInfo[] p = t.GetProperties();

foreach(PropertyInfo y in p)

{

if(y.Name == "Channel")

{

y.SetValue("Channel", c, null);       //Here is the problem!!

}

}

}

}
[/CODE]

get this error:

Object does not match target type.

Please help!

Thanks

Lee