473,434 Members | 1,462 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,434 software developers and data experts.

Page.FindControl

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 think I can.

I've tried iterating through all the controls on the page, but - well - it
lies! If I add Page.Controls to the watch it says there's five, if I then
add .Item(3) - the html form control, and then add .Controls this is full of
more controls...

Can anyone help me?

Regards

Rob
Aug 13 '07 #1
4 2438
Rob Meade wrote:
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 think I can.

I've tried iterating through all the controls on the page, but - well
- it lies! If I add Page.Controls to the watch it says there's five,
if I then add .Item(3) - the html form control, and then add
.Controls this is full of more controls...
You have to make a recursive loop.

I think that's the only solution here.

--

Riki
Aug 13 '07 #2
Hi Rob,
FindControl method is always related to current Naming container. So if you
want to use plain ID as it is defined you will need to have reference to
control which is naming container for controls you are looking for.

You can also use whole unique ID from top level naming container (usually
page) or part of unique ID - but again you have to relate it to proper naming
container.

If unique ID of your control is built from several IDs it means it is in
hierarchy of naming containers. Each container will add its id followed by
separator (usually $) to final id of your control.

Say you have control with uniqueID ctl00$ctl00$ctl00$myLabel. You can find
this control by calling Page.FindControl("ctl00$ctl00$ctl00$myLabel") or if
you have reference to control ctl00$ctl00 (named for example myGridRow) you
can call myGridRow.FindControl("ctl00$myLabel").

Use tracing to see whole tree of controls including naming containers.

Regards,
Ladislav

"Rob Meade" wrote:
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 think I can.

I've tried iterating through all the controls on the page, but - well - it
lies! If I add Page.Controls to the watch it says there's five, if I then
add .Item(3) - the html form control, and then add .Controls this is full of
more controls...

Can anyone help me?

Regards

Rob
Aug 13 '07 #3
"Riki" wrote...
You have to make a recursive loop.

I think that's the only solution here.
Yeah, thats what I thought - messy :o/

Thanks for your reply Riki,

Rob
Aug 14 '07 #4
"Ladislav Mrnka" wrote ...
Say you have control with uniqueID ctl00$ctl00$ctl00$myLabel. You can find
this control by calling Page.FindControl("ctl00$ctl00$ctl00$myLabel") or
if
you have reference to control ctl00$ctl00 (named for example myGridRow)
you
can call myGridRow.FindControl("ctl00$myLabel").

Use tracing to see whole tree of controls including naming containers.
Hi Ladislav,

Thanks for the reply.

I should have been more clear in my post, its actually me making the
multi-part id's for the controls, not .Net because they are in other
controls etc....

I am using various ID's from my database content and using them in the id's
of the controls.

Thanks for the information though - very useful.

Regards

Rob
Aug 14 '07 #5

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

Similar topics

4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
9
by: nail | last post by:
Hi. So I have a default.aspx page and 3 WebUserControls In the WebUserControl1, I have on TexBox, and in the default.aspx page I have a Button control. On the click event of the default.aspx page...
2
by: sck10 | last post by:
Hello, I am looping through each control using the following to find a particular control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"). For ctrRow = 1 To 3 strForLoop1 = "0" &...
5
by: Howard | last post by:
i have a default.master and default.aspx in default.aspx i would like to access a variable in default.master pageTitle public partial class _Default : System.Web.UI.Page { protected void...
9
by: D. Shane Fowlkes | last post by:
(ASP.NET 2 / VB) Question - How can I write a If statement to see if a control (textbox) actually exists on a page? Upon page_load, a certain control may or may not be visible on the page so I...
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...
2
by: jaffar.kazi | last post by:
Hi, What is the exact name to use to get a control reference on an asp.net page using FindControl? My experience is the following: 1. Page.FindControl does not work; it always returns null, even...
6
by: =?Utf-8?B?SmF5IFBvbmR5?= | last post by:
I am trying to access a Public property on a Master Page from a Base Page. On the content pages I have the MasterType Directive set up as follows: <%@ MasterType virtualpath="~/Master.master" %>...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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...
1
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
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.