Problem Passing control as a param into a class function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to make use of the following type of code in a ".cs" class. I
need to pass the Page.Controls collection into a class located in a ".cs"
file (not code behind). I am able to do this with the this mechanism but I
need to do it as a reference or out type.

My goal is to use a database table to do pre button security lookups and
disable
any button that the user does not have security for.

I would be very greatful for any input. Even a better mouse trap.

Thanks in advance
Grosch

foreach (Control c in Page.Controls)
{
foreach (Control childc in c.Controls)
{
if (childc is Button)
{
string sID = childc.ID.ToString();
//do db button lookup and disable if necessary
}
}
}
 
I am able to do this with the this ­mechanism but I need to do it as
a reference or out type.

Why? I would think that you just need to declare a parameter of type
ControlCollection and that's that. What kind of problem do you run into
if you don't make it "ref" or "out"?
 
Bruce Wood said:
a reference or out type.

Why? I would think that you just need to declare a parameter of type
ControlCollection and that's that. What kind of problem do you run into

ControlCollection with ref yields the following errors.
t.aspx.cs(50,40): error CS0206: A property or indexer may not be passed as
an out or ref parameter
y.cs(40,35): error CS0117: 'System.Web.UI.ControlCollection' does not
contain a definition for 'Controls'




if you don't make it "ref" or "out"?
It did however work with out the ref. Thank you very much. One thing
Visible exposed but enabled was not.


Thanks again, I hit the wall on this one. I am still at the humble level of
C#
 
Back
Top