Find Control in .NET

It is a way of handling Nested control (NET controls on NET Container Controls) because these nested controls are never available in coding hence we need to find them before using them like normal controls.

Suppose you have a Asp.NET Linkbutton named “lnkSubCategory” and you have placed that in a repeater control named “rptCategories”. Now when you want to change the URL of that LinkButton or even want to change the text of that and you start writing name of that linkbutton in code behind file of that page but server will start displaying “lnkSubCategory is not declared” error.

You will have to ‘find that control’ first and you ned to find that linkbutton on some event of your repeater control. Suppose we have a method of Databinding of repeater so you can find your linkbuuton in that method. in our example we need to write line


Dim lnkSubCat as linkButton= Ctype(e.FindControl(“lnkSubCategory “), LinkButton)


Now you can user lnkSubCat and can use now as a normal LinkButton control.


Cheers and Happy Coding.

Leave a Reply

Your email address will not be published. Required fields are marked *