Loop Through Server Control - Refer Code (VB.NET)

S

Sudhakar S P

-----------------------------------------------------------------------------
Thought of posting this code because lot of people are discussing about it,
I hope this will help someone who is looking for the code. - Sudhakar
-----------------------------------------------------------------------------
Private Sub LoopThroughControls()
Dim ctlTxt As spkTextBox
Dim ctlBtn As spkButton
Dim ctlLbl As spkLabel
Dim Form As HtmlForm
Dim ctl As Control

Try
For Each ctl In Page.Controls
If ctl.GetType.Name.ToUpper = "HTMLFORM" Then
Form = CType(ctl, HtmlForm)
Exit For
End If
Next
If Not Form Is Nothing Then
For Each ctl In Form.Controls
Select Case ctl.GetType.Name.ToUpper
Case "SPKTEXTBOX"
ctlTxt = CType(ctl, spkTextBox)
Case "SPKBUTTON"
ctlBtn = CType(ctl, spkButton)
Case "SPKLABEL"
ctlLbl = CType(ctl, spkLabel)
Case Else
'DO NOTHING
End Select
Next
End If
Catch ex As Exception
Throw ex
End Try
End Sub
-----------------------------------------------------------------------------
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top