On May 6, 3:05*pm, <msnews.microsoft.comwrote:
Problem is, even the placeholder control is dynamically created so I can't
reference it in the code. *Any thoughts?
"Madhur" <s...@df.comwrote in message
news:uM**************@TK2MSFTNGP03.phx.gbl...
FindControl does not search recursively.
You need to do RepeaterControl.FindControl("textbox1") instead of
Page.FindControl ("textbox1").
--
Madhur
<msnews.microsoft.comwrote in message
news:Os****************@TK2MSFTNGP05.phx.gbl...
Sorry, the controls are dynamically created and placed in a PlaceHolder
control. *Does there have to be some sort of looipng to find the control?
<msnews.microsoft.comwrote in message
news:OG**************@TK2MSFTNGP06.phx.gbl...
I dynamically create controls (textboxes) in a repeater control. *I know
their names (eg. TextBox1). *How do I find the text of TextBox1 in the
Form? FindControl does not seem to work.- Hide quoted text -
- Show quoted text -
Hi,
In this case first of all you need to recreate ALL the controls in
postback.
Here is a piece of code I use to create and fill a repeater in code.
There are some classes of mine that I use (cause I bind to a
collection of business objetcs) that yo will not have, but you will
get the idea of how it is done.
List<ControlCreateRepeaterItemsControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("<tr class=
\"RoleControlRepeaterRowCssClass\"><td align=\"right\" style=\"width:
50%\">"));
Control c = new Label();
c.ID = "RoleNameLBL";
controlsInRow.Add(c);
controlsInRow.Add(new LiteralControl("</td><td align=\"left
\" style=\"width: 50%\">"));
c = new CheckBox();
c.ID = "RoleStatusCHK";
controlsInRow.Add(c);
spanDiv = new HtmlGenericControl();
spanDiv.ID = "SpanDiv";
spanDiv.Style.Add("visibility", "hidden");
messageLBL = new Label();
messageLBL.ID = "MessageLBL";
spanDiv.Controls.Add(messageLBL);
controlsInRow.Add(spanDiv);
controlsInRow.Add(new LiteralControl("</td><td></td></
tr>"));
return controlsInRow;
}
List<ControlCreateRepeaterHeaderControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("<table width=\"100%
\">"));
return controlsInRow;
}
List<ControlCreateRepeaterFooterControls() {
List<ControlcontrolsInRow = new List<Control>();
controlsInRow.Add(new LiteralControl("</table>"));
return controlsInRow;
}
//The delegate declaration for the above methods
delegate List<ControlRepeaterControlCreator();
//This is the class that implement the template for each row
of the repeater
class RepeaterTemplate: ITemplate {
RepeaterControlCreator controlCreator;
public RepeaterTemplate(RepeaterControlCreator
controlCreator) {
this.controlCreator = controlCreator;
}
public void InstantiateIn(System.Web.UI.Control container)
{
foreach (Control c in controlCreator())
container.Controls.Add(c);
}
}
protected override void CreateChildControls() {
base.CreateChildControls();
roleLST = new Repeater();
roleLST.ItemDataBound += new
RepeaterItemEventHandler(RoleLST_ItemDataBound);
roleLST.HeaderTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterHeaderControl s)) ;
roleLST.ItemTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterItemsControls ));
roleLST.AlternatingItemTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterItemsControls ));
roleLST.FooterTemplate = new
RepeaterTemplate( new
RepeaterControlCreator(CreateRepeaterFooterControl s));
Controsl.Add( roleLST);
}
protected void OkBTN_Click(object sender, EventArgs e) {
//update the status
int index = 0;
foreach (RepeaterItem rItem in roleLST.Items) {
CheckBox cb = rItem.FindControl("RoleStatusCHK") as
CheckBox;
}