Dynamic controls

G

Guest

Hi all,
I'd like to fill text property in LinkButton.

For example:
int i = 3;
this.Controls["myLinkButton" + i.ToString()].Text = i.ToString();

Unfortunatelly this doesn't work for .NET 2.0.
I used "findIDControl" ... and I find it ! (all well),
..... but there isn't the Text property :( ...
there is only Visible and some other property.

Can you help me ?
Thanks in advance.
//LD
 
G

Guest

You need to cast the control that is returned by the FindControl method
otherwise it just returns a generic asp.net control object.

Example in C#

TextBox MyTextBox = (TextBox)ParentControl.findcontrol("Childcontrol");
MyTextBox.Text = "SomeWords";

You could also do something like:

((TextBox)ParentControl.FindControl("Childcontrol")).Text = "SomeWords";

But i think this makes the code less readable.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top