Thursday, April 20, 2006

How to find a control in .NET given the control name.

Situation:
I've a lot of buttons in a Panel whose names are Button1 Button2 ...
I want to programatically change the Caption and the click event.

Problem:
How do I get the control from the control name.

Solution:
private Control FindControl(String ctrlName)
{
foreach(Control ctr in this.panelGeneral.Controls)
if (ctr.Name == ctrlName)
return ctr;
return null;
}


© Copyright 2006. Bipin C Nair. All rights reserved.

0 Comments:

Post a Comment

<< Home