Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Page.FindControl for not a full name

Posted on 2006-06-20
5
Medium Priority
?
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

722 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