Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Referencing Dynamically added content

  Asked By: Bastet    Date: Mar 24    Category: Asp.net    Views: 785
  

I'm having this trouble referencing the type of control that I
render. Here is the code that i use to either add a ListBox or a
DropDownList to a place holder...


if (EventType == "VERSUS"){
DropDownList ddlOpponent = new DropDownList();
OpponentPlaceHolder.Controls.Clear();
OpponentPlaceHolder.Controls.Add(ddlOpponent);
}else if (EventType == "MULTIPLE"){
ListBox ddlOpponent = new ListBox();
ddlOpponent.SelectionMode = ListSelectionMode.Multiple;
OpponentPlaceHolder.Controls.Clear();
OpponentPlaceHolder.Controls.Add(ddlOpponent);
}

How could I then reference this control ddlOpponent and pass it to a
function that takes a list or dropdown to a method, such as the
following?

Call: BindList(ddlOpponent);
Method: private void BindList(TextBox ddlOpponent){}

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Perdita Lopez     Answered On: Mar 24

If I'm thinking of your problem correctly - you want to later (perhaps in
another function) - pull this dynamically  created control  out of the page's
bag-o-controls & use it. If this is on the right path, then you can use the
FindControl method  of the Control class...

Control myControl1 = FindControl("TextBox2");

Then you can use myControl1 just as you would use (in this example) the
original control, TextBox2

 
Didn't find what you were looking for? Find more on Referencing Dynamically added content Or get search suggestion and latest updates.




Tagged: