need help writing to a control

  • Thread starter Thread starter Robert Megee
  • Start date Start date
R

Robert Megee

If i create a textbox tb1,
I can write to it as such:

tb1.Text = "mytext";

I can make it visible:
tb1.Visible = true;

or invisible:
tb1.Visible = false;

Thanks to a posting here from a previous
question, I can reference that control
indirectly to set it visible:

string st1;

st1 = "tb1";

FindControl(st1).Visible = true;

But, this doesn't work:

FindControl(st1).Text = "mytext";

Is there a way to set the text of a control in an indirect
way?

thanks,

Robert
 
Visible is inherited from Control and since FindControl returns a Control,
you can use the Visible property.

Text, on the other hand, is a TextBox property, not inherited from Control
so you have to cast your Control as a TextBox to see Text:

((TextBox) FindControl(st1)).Text = "mytext";

DalePres
MCAD, MCDBA, MCSE
 
Great! I'll give it a try!

Thanks!

Robert
Visible is inherited from Control and since FindControl returns a Control,
you can use the Visible property.

Text, on the other hand, is a TextBox property, not inherited from Control
so you have to cast your Control as a TextBox to see Text:

((TextBox) FindControl(st1)).Text = "mytext";

DalePres
MCAD, MCDBA, MCSE
 
Back
Top