Iterate through page controls

A

Avon

Hi friends,

I need of some help,

I have this code:



For Each t As TextBox In Page.Controls ' here is the error



t.Text = "test"

Next



But I am getting this error:

Unable to cast object of type 'ASP.masterpages_maindesign_master' to type
'System.Web.UI.WebControls.TextBox'.





Please help me to understand this error and solve the problem

Thanks in advance
 
N

Nathan Sokalski

I would use an If statement inside the loop to check the type. For example,
try putting this If statement inside the For loop:


If t.GetType().ToString()="System.Web.UI.WebControls.TextBox" Then

End If


Then put any code you want inside the If statement so that the code will
only be executed on TextBox Controls. Good Luck!
 

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
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top