473,804 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(tes tvariable);
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 5710
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*******@dotn et247.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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(tes tvariable);
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*******@dotn et247.com> wrote in message
news:%2******** ********@TK2MSF TNGP10.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(tes tvariable);
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
3700
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 discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
0
325
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 Product table also, a dropdownlist in the EditItemTemplate has OrderID displayed from Orders table. I want to pass this data (insert), after changing info in textboxes within datalist editItemTemplate, as necessary, to the Order Details table. ...
0
2205
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 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_NAME") %>'><asp:label> </itemtemplate> <edititemtemplate>
2
5040
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" oneditcommand="GLRulesGrid_Edit"
3
2218
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 Page.FindControl in the following code: ******************************************
11
1899
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. Thank you. string option = ((TextBox)dgDropDownMenus.Items.FindControl("txtName")).Text; -----------------------DataGrid------------------------------------------- <asp:datagrid id="dgMenus" style="Z-INDEX: 101; LEFT: 0px; POSITION:
5
4122
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. My site uses Master pages and user controls. On an Advanced Search page I have numerous entry boxes and listboxes (keywords, categories, etc.) which are primarily standard HTML. I post this page to a different page which lists results and...
4
2988
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 = Page.Master.FindControl("CenterPanelContent $ItemBuilderWizard $StepNavigationTemplateContainerID $StepNavFinalStepButton") as Panel;
9
2191
by: AAaron123 | last post by:
I'm this far in determining the correct code to find a textbox I need to set. Me.Master.FindControl("Body1").FindControl("Form2").FindControl("Table2").FindControl("TableRow7").FindControl("TableCellR7C2S2").FindControl("RightCPH").FindControl("div1").FindControl("div2").FindControl("LoginView1") Took me longer than I want to say to produce the above and I'm not there yet.
0
9576
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10568
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10323
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10311
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7613
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4292
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3813
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2988
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.