473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

FindControl with a string variable as the parameter

In trying to create a Panel object with the FindControl methodusing a string variable as the paramater. The code is below. The variable 'testvariable' is equal to pnl_0 which is anexisting Panel on my page. It appears that I am unable to use avariable as the parameter for the method as I get the followingerror 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 playingaround with it for the last litte while and cannot find a workaround.

--------------------------------
From: Mark D'Souza

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>8y1KSNxwBE+cBLHU1Jbg8w==</Id>
Nov 16 '05 #1
2 5678
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>
Nov 16 '05 #2
Try setting testvariable equal to pnl_0.Name.

Bob Calvanese

"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>
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
0
by: rodneybauer1 | last post by:
i tried explaining this yesterday...here's a better formed question. thanks using Northwind sql database, and an oledb connection to it a datalist is bound to the productID and ProductName of the...
0
by: George Durzi | last post by:
cross posted in datagrid group. Inside <columns/> in my datagrid, I have the following template column <asp:templatecolumn HeaderText="To Be Completed By"> <itemtemplate> <asp:Label...
2
by: zambizzi | last post by:
....I can't seem to get my hands on a control I'm loading in an editable datagrid. Here's my datagrid control: <asp:datagrid id="GLRulesGrid" runat="server" autogeneratecolumns="False"...
3
by: tshad | last post by:
I have a .ascx file that I converted to a class. But I am getting the following error: error BC30469: Reference to a non-shared member requires an object reference. The error is for the...
11
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I am trying to get the text of an item in a GridView, but am doing something wrong. Can someone help me with the correct C# statement I need? Below is my GridView and my attempt to get the control....
5
by: John Kotuby | last post by:
Hi all, After more than a year programming with ASP.NET 2.0 and VB I am still finding it difficult to leave some habits from classic ASP behind. this is particularly true with cross-page posting....
4
by: Hillbilly | last post by:
Maybe this is or isn't some kind of bug but it sure is goofy and remains a mystery that really has me puzzled for two reasons... // goofy syntax functions as expected... Panel finalStepButton =...
9
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.