First, it is a good idea to test for null on the results of FindControl in
case the object is not found.
I tried your code with no problems. I created the variable testvariable and
assigned the string "pnl_0" to it. I successfully found the panel with
FindControl. I also set testvariable = pnl_0.ID and was able to return the
panel.
If you're not able to locate your panel with FindControl, you have either
mispelled your ID when assigning the value to testvariable, or your panel is
not at the Page level. Make sure it is not a child control of some other
container. If it is a child control, you'll have to do a recursive search
to get to your pnl_0.
HTH
DalePres
MCAD, MCDBA, MCSE
"Mark D'Souza via .NET 247" <an*******@dotnet247.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
In trying to create a Panel object with the FindControl method using a
string variable as the paramater. The code is below. The variable
'testvariable' is equal to pnl_0 which is an existing Panel on my page. It
appears that I am unable to use a variable as the parameter for the method
as I get the following error message:
"Object reference not set to an instance of an object"
CODE:
Panel pnl = (Panel) FindControl(testvariable);
pnl.Visible = false;
Any assistance would be greatly appreciated. I'm been playing around with
it for the last litte while and cannot find a work around.
--------------------------------
From: Mark D'Souza
-----------------------
Posted by a user from .NET 247 (
http://www.dotnet247.com/)
<Id>8y1KSNxwBE+cBLHU1Jbg8w==</Id>