Request for a Better FindControl Method in ASP.NET


I'm spending hours trying to get a reference to a FileUpload control that's inside an InsertTemplate which is inside a Panel which is inside a Listview which is inside a Panel in an ASP.NET ContentPlaceHolder.

It's crazy to have to figure out all these naming containers (and parents, grandchildren, cousins, and in-laws) manually when ASP.NET creates the control structure and knows perfectly well where things are and what they're called.

Therefore, it would be nice to have a better FindControl method that would automatically (using LINQ?) do the recursion to come up with the control reference. You'd just pass in the control ID as a string.

When I look at the browser DOM's document.getElementId("txtJLLAmt1")  I have to think this could be built into ASP.NET. Here's a post with the basic idea that the ASP.NET Team could build on:


Thanks for listening. I feel better having ranted - even though I don't have the problem solved.



  • Thanks for the link. It leads to other useful routines.

    I still think this capability should be built into ASP.NET itself. The ASP.NET team could implement the most efficient solution and make it available for everyone.


  • If your using .NET 3.5, you could use an extension method to handle this same functionality.

    I find extension methods a huge addition to the framework in 3.5.

  • Thanks. I went with the LINQ solution based on the code in the blog I referenced. I call it like this:

    FileUpload flup = ListView1.Controls.All().OfType().FirstOrDefault();

    It works fine and is quick to code, but I'm afraid a LINQ implementation might be overly resource-intenstive for a busy production site.


  • I just used Reflector to find the sealed version that does this, and it works like a champ. I forget where I found it, but I recall looking around validators or something, which have to find the control they validate by ID.

Comments have been disabled for this content.