How to find a LinkLabel or Button on TabPage

156 Views Asked by At

I'm trying to put dynamicaly a LinkLabel (also I traied to put a button) in a TabPage:

LinkLabel newLinkLabelButton = new LinkLabel();
newLinkLabelButton.Text = "Login";
newLinkLabelButton.Name = "linkLabel_11";
tabs.TabPages[0].Controls.Add(newLinkLabelButton);

Now I'm trying to find this control on the specificf TabPage with function

newLoginLinkLabel = (LinkLabel)Helper.GetLinkLabelByTagAndfamily(tabs.TabPages[0], _name);

where the function body is:

public static Control GetControlByTagAndfamily(TabPage _tab, string _name)
{
  Control rez = new Control();
  foreach (Control ctrl in _tab.Controls)
  {
      if (ctrl.Name == _name)
      {
        rez = ctrl;
        break;
      }
   }
   return rez;
}

But the function never founds a LinkLabel or a Button inside _tab.Controls collection. I observed the collection contains founds Labels only, if I trying to find some labels inside.

Pleas help to solve this.

1

There are 1 best solutions below

0
kirpi4 On

Well, my problem is solved, the code above is correct. The problem was in wrong _name calculation before using it in

GetControlByTagAndfamily(TabPage _tab, string _name);