Solved

Page.FindControl for not a full name

Posted on 2006-06-20
5
356 Views
Last Modified: 2012-06-22
Hello,

Can I find a control using Page.FindControl() if I don't know the full name? I know only part of it, this part is unique, so it won't appear in any other control id.

thanks,
yurich
0
Comment
Question by:Yurich
  • 3
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
kGenius earned 500 total points
ID: 16941166
Haven't tested it, just a thought:

Loop through the controls

Public Function FindControls(ByVal parent As Control) As Control
For each ctrl As Control In parent.Controls
  If ctrl.ID.IndexOf("YOUR PART OF ID") > -1 Then
    return ctrl
    Exit Function
  End If
  If ctrl.HasControls Then
     FindControls(ctrl)
  End If
Next
return Nothing
End Function

maybe still some errors, but it's a first thought
kGenius
0
 
LVL 21

Author Comment

by:Yurich
ID: 16941217
I actually started from this iteration, but apparently in my case it's a bit more complicated as I have not asp-control table on my page, where among other controls, asp and html ones, I have my control. So, it should be more thorough iteration first (checking for not asp controls as they can through exceptions), and second I would use it only if I can't find a way to twick this FindControl function.

Thanks,
Yurich
0
 
LVL 7

Expert Comment

by:kGenius
ID: 16942166
can you post your code?
0
 
LVL 21

Author Comment

by:Yurich
ID: 16958869
I guess I'll have to iterate after all...

kG, your function is actually not recursive... it will return the first control that has a matching ID and terminate the recursion on that. If I have my control not first, it will not pick it up.

I found a simple way to work out this by using a few if-elses, but still need to do recursion to reset attributes of all controls of this type to default values.

regards,
yurich
0
 
LVL 21

Author Comment

by:Yurich
ID: 17034169
I've done it some time ago already but never had time to get back to the question. Thank you for your input.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question