Object Argument

  • Thread starter Thread starter Alex Sauceda
  • Start date Start date
A

Alex Sauceda

Hi,

I'm trying to create a procedure like this one:

protected Boolean test(object C, string id) {
if (C.FindControl(id) is Label)
{
return true;
}
}

I'm getting this error "Error 1 'object' does not contain a definition for
'FindControl' "

This code is working fine with VB. Does anyone knows how to fix this?

Regards,

Alex
 
Alex Sauceda said:
I'm trying to create a procedure like this one:

protected Boolean test(object C, string id) {
if (C.FindControl(id) is Label)
{
return true;
}
}

I'm getting this error "Error 1 'object' does not contain a definition for
'FindControl' "

This code is working fine with VB.

Only with Option Strict Off, I suspect.
Does anyone knows how to fix this?

What type are you expecting C to be? Cast it to that type, or change
your method to take the appropriate type in the first place.
 
I want to pass a webcontrol like a panel or a repeateritem so I can look for
a control contained inside the object.
 
Use the base type for controls; Control, intead of Object. The
FincControl method is defined in the Control class, so you can use it
regardless of the actual class of the control.

Alex said:
I want to pass a webcontrol like a panel or a repeateritem so I can look
for a control contained inside the object.
 
Great, thanks a lor for your help!

Göran Andersson said:
Use the base type for controls; Control, intead of Object. The FincControl
method is defined in the Control class, so you can use it regardless of
the actual class of the control.
 
Alex Sauceda said:
Great, thanks a lor for your help!

And as an aside, I *strongly* recommend that you turn Option Strict On
in your VB.NET code apart from occasions where it's helpful to have
weak typing (e.g. Office interop). It's faster as well as being more
type-safe, and you'll have Intellisense to help you.
 
Back
Top