473,657 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

FindControl doesn't work

I'm trying to use FindCrontrol and it will not work. Here is the code:

Dim DisplayPanel As Panel
DisplayPanel = CType(FindContr ol("pnlName"), Panel)

No matter how I do it - I've tried Me.FindControl, Page.FindContro l,
just plain FindControl the DisplayPanel variable is always Nothing
after the code execute. The panel does exist with the name "pnlName"
and I can use that just fine in code. If I break the code, the Parent
that is given for the panel is "Content1", but I can't reference
Content1 in the code.

I've tried other controls of different types and I get the same thing
every time. What am I missing?

Aug 11 '06 #1
24 2271
Dim c As System.Web.UI.C ontrol
Dim ctlToFind As Panel
c = Me.Parent
While ctlToFind Is Nothing
ctlToFind = CType(c.FindCon trol("pnlName") , Panel)
c = c.Parent
End While

Aug 11 '06 #2
FindControl only works on the immediate Controls inside a Coontrol. Controls
are nested inside other Controls, so you need to use recursion to find the
Control if you don't know the exact Control it is immediately inside.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Dennis" <db********@gma il.comwrote in message
news:11******** *************@m 79g2000cwm.goog legroups.com...
I'm trying to use FindCrontrol and it will not work. Here is the code:

Dim DisplayPanel As Panel
DisplayPanel = CType(FindContr ol("pnlName"), Panel)

No matter how I do it - I've tried Me.FindControl, Page.FindContro l,
just plain FindControl the DisplayPanel variable is always Nothing
after the code execute. The panel does exist with the name "pnlName"
and I can use that just fine in code. If I break the code, the Parent
that is given for the panel is "Content1", but I can't reference
Content1 in the code.

I've tried other controls of different types and I get the same thing
every time. What am I missing?

Aug 11 '06 #3
fa*******@gmail .com wrote:
Dim c As System.Web.UI.C ontrol
Dim ctlToFind As Panel
c = Me.Parent
While ctlToFind Is Nothing
ctlToFind = CType(c.FindCon trol("pnlName") , Panel)
c = c.Parent
End While

Thanks, but that doesn't work because Me.Parent is nothing. This is in
the page_load event and the panel is on the page itself, not contained
in another control, if that makes a difference.

Aug 11 '06 #4
Kevin Spencer wrote:
FindControl only works on the immediate Controls inside a Coontrol. Controls
are nested inside other Controls, so you need to use recursion to find the
Control if you don't know the exact Control it is immediately inside.
Thanks, but this doesn't help me. The control I'm looking for isn't
inside any other control - it's on the page itself. If I look in the
locals window when I break into the code, the parent is listed as
"Content1" as I said. There isn't any control called "Content1" that I
can reference.

Aug 11 '06 #5
e.Item.FindCont rol

"e" is the name of the DataGrid's event argument.
"Item" refers to the current row within the DataGrid.


<fa*******@gmai l.comwrote in message
news:11******** **************@ 75g2000cwc.goog legroups.com...
Dim c As System.Web.UI.C ontrol
Dim ctlToFind As Panel
c = Me.Parent
While ctlToFind Is Nothing
ctlToFind = CType(c.FindCon trol("pnlName") , Panel)
c = c.Parent
End While

Aug 11 '06 #6
Scott M. wrote:
e.Item.FindCont rol

"e" is the name of the DataGrid's event argument.
"Item" refers to the current row within the DataGrid.
I'm not using a datagrid. The control I want to find is directly on
the page. It is not contained in a datagrid, formview, or any other
control. I want to do this in the page_load event.

Aug 11 '06 #7
In fact, the WebForm is inside the Page, which is also a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Dennis" <db********@gma il.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
Kevin Spencer wrote:
>FindControl only works on the immediate Controls inside a Coontrol.
Controls
are nested inside other Controls, so you need to use recursion to find
the
Control if you don't know the exact Control it is immediately inside.

Thanks, but this doesn't help me. The control I'm looking for isn't
inside any other control - it's on the page itself. If I look in the
locals window when I break into the code, the parent is listed as
"Content1" as I said. There isn't any control called "Content1" that I
can reference.

Aug 11 '06 #8
The Control must be inside the WebForm, which is a Control.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Surgery

Orange you bland I stopped splaying bananas?
"Dennis" <db********@gma il.comwrote in message
news:11******** **************@ i3g2000cwc.goog legroups.com...
Kevin Spencer wrote:
>FindControl only works on the immediate Controls inside a Coontrol.
Controls
are nested inside other Controls, so you need to use recursion to find
the
Control if you don't know the exact Control it is immediately inside.

Thanks, but this doesn't help me. The control I'm looking for isn't
inside any other control - it's on the page itself. If I look in the
locals window when I break into the code, the parent is listed as
"Content1" as I said. There isn't any control called "Content1" that I
can reference.

Aug 11 '06 #9
Kevin Spencer wrote:
The Control must be inside the WebForm, which is a Control.
So how do I reference the WebForm in the code?

Aug 11 '06 #10

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

Similar topics

1
7759
by: James G. Beldock | last post by:
I have seen the following behavior: when issuing a Page.FindControl() for a control which exists in an item template (from within an ItemDataBound() event, for example), I get nulls back regularly. Has anyone seen this before? It's pretty aggravating to have to iterate through the controls in each grid cell to find the ones I need, especially since finding those cells is not always easy. Here's my ItemDataBound() handler: private void...
0
1758
by: Harry F. Harrison | last post by:
Here's the situation...Context - Using an Inherited WebControl object as a base for server custom controls. In a web custom control, whenever I create a child control and add it to the Controls class, it takes 3 lines of code. Example: Dim TextBox as System.Web.UI.WebControls.TextBox 1..TextBox = New System.Web.UI.WebControls.TextBox
3
1385
by: Andrea Williams | last post by:
Ok, thanks to a kind person yesterday, I've started using the FindControl() method. Although I able to get this to work for Web Controls, I'm unable to find the HTML Controls? Am I missing something still? Do I really have to use the Web controls in order to be able to change properties on the control? I'm trying to create a user control and have the apsx page include that control, but change a few properties, like the Table Border...
2
7534
by: Bruno Alexandre | last post by:
Hi guys, I have this code: Dim gv As GridViewRow Dim str As String = "" Dim dd As DropDownList For Each gv In gvItems.Rows If gv.RowType = DataControlRowType.DataRow Then
4
5667
by: Dave | last post by:
If you had a FileUpload control inside of a FormView...how would you use FindControl to access the FileUpload properties? Let me just say that (FileUpload)FormView1.FindControl(FileUpload1).FileName doesn't work. The purpose is to insert a graphic in the InsertItemTemplate section of the form. I'm using the expample that's in the online help for the post back. protected void Page_Load(object sender, EventArgs e)
4
14982
by: Jim McGivney | last post by:
I am trying to form a string by concatenating the Text strings of a number of Label controls. The Labels are Label33 to Label64. I thought I would use a For Loop to increment through the labels. The code below does not work as Text is not a recognized property of myControl, which is the name of the control fetched by FindControl. Any suggestions as to how to use FindControl to obtain the Text value of the found control would be...
1
1327
by: divingIn | last post by:
Hi, I have a master page and a content page. From my content page i can access the master page controls using Master.FindControl() but i cannot access controls from my content page using FindControl(). For any control it just returns null. I have been trying for so long with no success. so frustrated! Please help. eg. FindControl("Table_Search") and FindControl("Content1") returns null. <CODE> <%@ Page Language="C#"...
7
5691
by: AAaron123 | last post by:
Me.FindControl("MissionScheduleID"), below returns null. Do you know what I'm doing wrong? Thanks ***In my .aspx file I have: asp:Content ID="Content3" contentplaceholderid="MainMasterLeftDataID" runat="server">
9
2182
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
8411
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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
8613
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2740
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
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1732
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.