Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3277304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:21:12+00:00 2026-05-17T19:21:12+00:00

I ran into a situation where FindControl was returning a control that wasn’t a

  • 0

I ran into a situation where FindControl was returning a control that wasn’t a complete match of the Id I was searching by. There are two controls in the parentcontrol with similar Ids like: “MyControl” and “MyControlAlternate”. When I call FindControl(“MyControl”) the control returned is “MyControlAlternate”. I was wondering if anyone had any explaination why or thoughts as to what might be causing this problem. The way I got around this was implementing my own version of FindControl.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T19:21:13+00:00Added an answer on May 17, 2026 at 7:21 pm

    The default behavior of FindControl to use its own naming container. If that doesn’t work it tries to do pattern matching on the name. That would explain why you are getting the wrong control – your naming container is incorrect and the code is making it into the pattern matching phase.

    Here is the dissassembly of FindControl from Reflector:

    Public Overridable Function FindControl(ByVal id As String) As Control
        Return Me.FindControl(id, 0)
    End Function
    
    Protected Overridable Function FindControl(ByVal id As String, ByVal pathOffset As Integer) As Control
        Dim str As String
        Me.EnsureChildControls
        If Not Me.flags.Item(&H80) Then
            Dim namingContainer As Control = Me.NamingContainer
            If (Not namingContainer Is Nothing) Then
                Return namingContainer.FindControl(id, pathOffset)
            End If
            Return Nothing
        End If
        If (Me.HasControls AndAlso (Me._occasionalFields.NamedControls Is Nothing)) Then
            Me.EnsureNamedControlsTable
        End If
        If ((Me._occasionalFields Is Nothing) OrElse (Me._occasionalFields.NamedControls Is Nothing)) Then
            Return Nothing
        End If
        Dim anyOf As Char() = New Char() { "$"c, ":"c }
        Dim num As Integer = id.IndexOfAny(anyOf, pathOffset)
        If (num = -1) Then
            str = id.Substring(pathOffset)
            Return TryCast(Me._occasionalFields.NamedControls.Item(str),Control)
        End If
        str = id.Substring(pathOffset, (num - pathOffset))
        Dim control2 As Control = TryCast(Me._occasionalFields.NamedControls.Item(str),Control)
        If (control2 Is Nothing) Then
            Return Nothing
        End If
        Return control2.FindControl(id, (num + 1))
    End Function
    

    Clearly what is happening in your example is that you are not specifying the correct naming container. However, without providing a code example I cannot be more specific than this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on optimizing a query and have ran into a situation that's
So odd situation that I ran into today with OrderBy: Func<SomeClass, int> orderByNumber =
I ran into a situation that seems to suggest otherwise. In the following code
I ran into a situation today where Java was not invoking the method I
A co-worker recently ran into a situation where a query to look up security
I ran into the problem that my primary key sequence is not in sync
I ran into an interesting behavior recently. It seems that if I override .equals()
I ran into the situation where my class is making one asynchronous web call
I ran into this situation today. I have an object which I'm testing for
I just ran into a situation where I needed to patch a release with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.