473,624 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How goofy can FindControl get anyway?

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.Fin dControl("Cente rPanelContent
$ItemBuilderWiz ard
$StepNavigation TemplateContain erID
$StepNavFinalSt epButton") as Panel;

// "normal form" object not found...
Panel finalStepButton =
Page.Master.Fin dControl("Cente rPanelContent")
..FindControl(" ItemBuilderWiza rd")
..FindControl(" StepNavigationT emplateContaine rID")
..FindControl(" StepNavFinalSte pButton") as Panel;

1.) Why does the $ delineator even allow finding the control server-side
when it is used to delineate the ClientID?

2.) Why does the $ delineator over-ride the normal form of FindControl at
all?

Ugly Betty or not, I'm just glad some "thing" works once in awhile :-)

Oct 11 '08 #1
4 2976
FindControl does not do recursive searches. it only searches the naming
container of the control its called from. to get around this limitation
FindControl also supports a fully qualified path. so if you want to find
ctl1 which is a child of parent1, and parent1 is a child of topparent,
and topparent is a control in the Page control collection, then you can
lookup ctl1 by its fully qualified path:

Page.FindContro l("topparent$pa rent1$ctl1")

if you are searching from topparent then its

FindControl("pa rent1$ctl1")
note: you can use ":" or "$" as a delimiter

-- bruce (sqlwork.com)

Hillbilly wrote:
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.Fin dControl("Cente rPanelContent
$ItemBuilderWiz ard
$StepNavigation TemplateContain erID
$StepNavFinalSt epButton") as Panel;

// "normal form" object not found...
Panel finalStepButton =
Page.Master.Fin dControl("Cente rPanelContent")
.FindControl("I temBuilderWizar d")
.FindControl("S tepNavigationTe mplateContainer ID")
.FindControl("S tepNavFinalStep Button") as Panel;

1.) Why does the $ delineator even allow finding the control server-side
when it is used to delineate the ClientID?

2.) Why does the $ delineator over-ride the normal form of FindControl
at all?

Ugly Betty or not, I'm just glad some "thing" works once in awhile :-)
Oct 11 '08 #2
Somewhere long ago I recall reading not to do that and got into the habit of
concatenating FindControl(".. .").FindControl ("...") on each part of the
tree.

The $ delineator had something to do with being used to find controls using
client-side code. Do you remember or know of the context I'm thinking about?
Do you think I'm confusing ClientID with some other context?

Again, the wierdest part is being able to use delineators but not
concatenating when concatenating functions as intended in other places in
the same code. This is all in Master Pages which may incur some of its own
wierdness.

"bruce barker" <no****@nospam. comwrote in message
news:%2******** ********@TK2MSF TNGP02.phx.gbl. ..
FindControl does not do recursive searches. it only searches the naming
container of the control its called from. to get around this limitation
FindControl also supports a fully qualified path. so if you want to find
ctl1 which is a child of parent1, and parent1 is a child of topparent, and
topparent is a control in the Page control collection, then you can lookup
ctl1 by its fully qualified path:

Page.FindContro l("topparent$pa rent1$ctl1")

if you are searching from topparent then its

FindControl("pa rent1$ctl1")
note: you can use ":" or "$" as a delimiter

-- bruce (sqlwork.com)

Hillbilly wrote:
>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.Fi ndControl("Cent erPanelContent
$ItemBuilderWi zard
$StepNavigatio nTemplateContai nerID
$StepNavFinalS tepButton") as Panel;

// "normal form" object not found...
Panel finalStepButton =
Page.Master.Fi ndControl("Cent erPanelContent" )
.FindControl(" ItemBuilderWiza rd")
.FindControl(" StepNavigationT emplateContaine rID")
.FindControl(" StepNavFinalSte pButton") as Panel;

1.) Why does the $ delineator even allow finding the control server-side
when it is used to delineate the ClientID?

2.) Why does the $ delineator over-ride the normal form of FindControl at
all?

Ugly Betty or not, I'm just glad some "thing" works once in awhile :-)
Oct 12 '08 #3


"Hillbilly" <so******@somew here.comwrote in message
news:Oy******** ******@TK2MSFTN GP05.phx.gbl...
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.Fin dControl("Cente rPanelContent
$ItemBuilderWiz ard
$StepNavigation TemplateContain erID
$StepNavFinalSt epButton") as Panel;

// "normal form" object not found...
Panel finalStepButton =
Page.Master.Fin dControl("Cente rPanelContent")
.FindControl("I temBuilderWizar d")
.FindControl("S tepNavigationTe mplateContainer ID")
.FindControl("S tepNavFinalStep Button") as Panel;

1.) Why does the $ delineator even allow finding the control server-side
when it is used to delineate the ClientID?

2.) Why does the $ delineator over-ride the normal form of FindControl at
all?

Ugly Betty or not, I'm just glad some "thing" works once in awhile :-)
I use the following as a replacement, it does a recursive search and returns
a typed control:

public static T FindControl<T>( System.Web.UI.C ontrol initialControl,
string id) where T : System.Web.UI.C ontrol
{
if (initialControl .ID == id && initialControl is T)
{
return initialControl as T;
}

System.Web.UI.C ontrolCollectio n controls = initialControl. Controls;
foreach (System.Web.UI. Control ctl in initialControl. Controls)
{
System.Web.UI.C ontrol nextCtl = FindControl<T>( ctl, id);
if (nextCtl != null)
{
return nextCtl as T;
}
}

return default(T);
}

You normally pass in the Page itself as the first parameter but you can
improve performance by starting lower down the tree if possible.
The generic parameter T specifies the type of control you are searching for.
If the control is not found then null is returned.

--

Joe Fawcett (MVP - XML)
http://joe.fawcett.name

Oct 13 '08 #4
<snip />

Thanks Joe, I've started to collect and study this recursive approach.
Oct 13 '08 #5

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

Similar topics

4
1826
by: Jozef | last post by:
Hello, I have forms in my database that use grey as the back color. When I convert them to XP, They all look goofy. The grey becomes two tone. The grey used in the controls are dark, the grey used in the form detail is light, almost white. I can change the back color on the forms to match the controls, but on controls like tabs etc, it still looks goofy (since I can't change the backcolor on a tab control or button etc.). Is there...
2
11175
by: MattB | last post by:
I've got some controls (mostly textboxes for now) that get created at runtime in a DataGrid. I create them using the OnItemDataBound event. I realize this isn't ideal, but I'm trying to see if I can make this work anyway. In a button click event I loop through the dataset the datagrid is bound to and try to use FindControl to get at my controls. Below is a snippet from the button click event: iRow = 0
2
3177
by: tparks69 | last post by:
All I need to do is set the border property of an image control to border=0. I want to do this at runtime for the first image on the page in a datalist. In the ItemCreated event I'm trying to use FindControl to set a reference to the img control so I can change the attribute. But when I run the code below I get the error: "Object reference not set to an instance of an object." I assume its not finding the control and returning null? ...
3
1567
by: clintonG | last post by:
What's with this software? Every day its a new surprise with some goofy bullsh!t. I finally make time to try to finish building out Membership logging and reporting and today its user data in the SQL Server 2005 aspnet_Membership table such as LastLockoutDate and FailedPassword with dates for all users entered as 1/1/1754. Not only is this goofy bullsh!t it is grossly incorrect goofy bullsh!t. I have used one of my three test users to...
0
1253
by: David Rees | last post by:
Before I was using LoadControl and a slew of User Controls to achive the same effect, but I realised a custom TemplatedControl was the better way of doing it. Anyway, this is the templated control's markup: <ams:Comments id="amsComments" runat="server"> <Header> <div id="CommmentList"> <h3 class="box">Article Comments</h3>
4
2455
by: Rob Meade | last post by:
Hi all, I was wondering if you can help. I have the need to find a control on the page for which I don't know all of the ID, this is because it is made up from several id's forming one new id. Is there anyway to find this control with only part of the information (the part I have will definately be unique). I was hoping that it might be possible to push a regular expression in the string part of the Page.FindControl - but I dont...
0
1567
by: =?Utf-8?B?VHJhY2tz?= | last post by:
Does the toolstripcontainer etc work at all? I want to save the settings for the toolstrip positions in my app so they start up with the saved positions. Tried using: ToolStripManager.SaveSettings(Me) in form.closing with ToolStripManager.LoadSettings(Me) in form load
4
2216
by: Dave | last post by:
I have a web page that I'm trying to toggle between current data and archived data. So far so good. To preserver the integrity of the archived data, I need to disable the Edit, Delete, and New links in the Form View. The below code is what I've been trying to use, and I've tried it in various events with no luck. I need some help. Control btn1 = this.fvCapture.FindControl("EditButton"); Control btn2 =...
1
1329
by: Mufasa | last post by:
I have a page that has a master page. I'm writing generic code to find multiple controls on the page (I have a number of controls called tbName1, tbName2, tbName3, ..., tbName20) and rather than doing all the same code for all 20 fields, I thought I'd write something that loops through all of the fields 'finding' the control as it goes. But if I do: TextBox tbNew = (TextBox) this.FindControl("tbName1"); It comes back as null. If I...
0
8233
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
8170
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
8675
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
8619
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
8334
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,...
0
8474
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
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2604
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
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.