Get value of a dynamic control

D

Dominic

..net newbie getting used to things and am in documentation overload.
Can't seem to find info on what should be a simple/common thing.

I've created a text input control on the fly:

Dim item As HtmlInputText = New HtmlInputText
item.ID = "testitem"
Page.Controls.Add(item)

How do I get the value (.text attribute) of this control using the
string value of the id/name ("testitem") as the reference?

Thanks in advance.
 
V

Victor Garcia Aprea [MVP]

Hi Dominic,

You use the FindControl method which takes a control ID and returns a
Control reference. You then cast that to your Control-derived type and
access any properties/methods you may need, ie:
[C#]
YourControlType ctrl = (YourControlType)FindControl("YourControlID");


--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
To contact me remove 'NOSPAM'. Please post all questions to the newsgroup
and not by private mail.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top