Finding control
-
I try to loop through the controls in the page and to identify certain controls, but I can't locate them. Here is my code: Protected Sub submitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitBtn.Click Dim errMsg As String = "" For Each ctrl As Control In Me.Controls If TypeOf ctrl Is TextBox Then errMsg &= "Found it!" Else errMsg &= "Nothing Found!" End If msgText.Text = errMsg Next End Sub When I trace the ctrl as String output I get ASP.masterpage_master
-
I try to loop through the controls in the page and to identify certain controls, but I can't locate them. Here is my code: Protected Sub submitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitBtn.Click Dim errMsg As String = "" For Each ctrl As Control In Me.Controls If TypeOf ctrl Is TextBox Then errMsg &= "Found it!" Else errMsg &= "Nothing Found!" End If msgText.Text = errMsg Next End Sub When I trace the ctrl as String output I get ASP.masterpage_master
Try by the Page.control
Sujit
-
Try by the Page.control
Sujit
-
Found the solution: Protected Sub submitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles submitBtn.Click Dim errMsg As String = "" Dim ctHolder As ContentPlaceHolder ctHolder = CType(Master.FindControl("ContentPlaceHolder1"), ContentPlaceHolder) For Each ctrl As Control In ctHolder.Controls If TypeOf ctrl Is TextBox Then errMsg &= "Found it!" & ctrl.ID.ToString() & "
" End If Next msgText.Text = errMsg End Sub Thanks so for the suggestion!