Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Page.FindControl for not a full name

Posted on 2006-06-20
5
Medium Priority
?
364 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 1500 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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