How to check if a control exists?

Q

Quentin Huo

Hi:

Some of my controls (e.g. TextBox, DropDownList, ...) are created
programmingly, so I have to check if a certain control exists, like:

if the TextBox control exists, get it value.
else ......


How can I do this?

Thanks

Q.
 
D

Dan Brussee

The FindControl method might work well for you.
For example:
If IsNothing(FindControl("TextBox1")) Then 'control doesn't exist

Here's more info:
http://msdn.microsoft.com/library/d...rfsystemwebuicontrolclassfindcontroltopic.asp


Of course if you are controlling whether the control exists or not,
then you should be able to decide if it is there, right? Not bashing
or anything, and I have been known to use this type of code, but you
should know if a control exists or not since you "programatically"
created it or set it to not display, eh?
 

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,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top