A
accyboy1981
Hi,
I'm creating an asp text box dynamically within an asp table. I know
the id as this is not dynamic (txBxPass). I need to get the text of
this text box when an asp button is pressed. I know that I need to
recursively go through the controls on the page but I'm having troble
with this. I think that the problem is that the control is within
another control (i.e. the text box being in the table). I've created
two methods but neither seem to work.
I call the methods by:
TextBox txtBxPass = getControl(this, "txtBxPass") as TextBox;
where "txtBxPass" is the text box name.
Below I have included both the methods I have created:
private Control getControl(Control parent, string id)
{
System.Web.UI.Control d = new Control();
foreach (Control c in this.Page.Controls)// parent.Controls)
{
if (c.ID == id )
{
d = c;
return d;
}
if (c.Controls.Count > 0)
{
d = getControl(c, id);
}
}
return d;
}
private Control getControl(Control s, string id)
{
foreach (Control ctrlControl in s.Controls)
{
if (ctrlControl.ID == id)
{
return ctrlControl;
}
getControl( ctrlControl, id );
}
return null;
}
Any help would be much appreciated.
Thanks
Simon
I'm creating an asp text box dynamically within an asp table. I know
the id as this is not dynamic (txBxPass). I need to get the text of
this text box when an asp button is pressed. I know that I need to
recursively go through the controls on the page but I'm having troble
with this. I think that the problem is that the control is within
another control (i.e. the text box being in the table). I've created
two methods but neither seem to work.
I call the methods by:
TextBox txtBxPass = getControl(this, "txtBxPass") as TextBox;
where "txtBxPass" is the text box name.
Below I have included both the methods I have created:
private Control getControl(Control parent, string id)
{
System.Web.UI.Control d = new Control();
foreach (Control c in this.Page.Controls)// parent.Controls)
{
if (c.ID == id )
{
d = c;
return d;
}
if (c.Controls.Count > 0)
{
d = getControl(c, id);
}
}
return d;
}
private Control getControl(Control s, string id)
{
foreach (Control ctrlControl in s.Controls)
{
if (ctrlControl.ID == id)
{
return ctrlControl;
}
getControl( ctrlControl, id );
}
return null;
}
Any help would be much appreciated.
Thanks
Simon