Click here to Skip to main content
16,016,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI
How do I access the properties of a dynamic controls(eg. textbox,dropdownlist) on a place holder in vb.net. I have strings of queries to run but the number and type of control depends on the parameter of the Query string. I have successfully created the controls but can not access their properties. When I loop through the place holder my control are not found.

Please I need a help.
Thanks in advance.
Posted
Comments
R. Giskard Reventlov 29-Mar-11 5:17am    
Look at ViewState
Sunasara Imdadhusen 29-Mar-11 5:32am    
Where is your code?
Gomda 29-Mar-11 7:08am    
Hi digital
ViewState is set to true
Gomda 29-Mar-11 7:12am    
Hi Sunasara Imdadhusen. find below my codes:

Function getPameterValue(ByVal ParentCtrl As Object, ByVal CtrName As String) As String
Dim childCtrl As Control
getPameterValue = ""

For Each childCtrl In ParentCtrl.Controls 'ParamPlaceHolder
If TypeOf childCtrl Is TextBox Then
If childCtrl.ID = CtrName Then 'Or childCtrl.UniqueID = CtrName
getPameterValue = "'" & CType(childCtrl, TextBox).Text & "'"
End If

ElseIf TypeOf childCtrl Is DropDownList Then
If childCtrl.ID = CtrName Then 'Or childCtrl.UniqueID = CtrName
getPameterValue = "'" & CType(childCtrl, DropDownList).SelectedItem.Value.ToString & "'"
End If

End If

Next childCtrl

Return getPameterValue
End Function

Function getPameterValue(ByVal ParentCtrl As Object, ByVal CtrName As String) As String
Dim childCtrl As Control
getPameterValue = ""

For Each childCtrl In ParentCtrl.Controls 'ParamPlaceHolder
If TypeOf childCtrl Is TextBox Then
If childCtrl.ID = CtrName Then 'Or childCtrl.UniqueID = CtrName
getPameterValue = "'" & CType(childCtrl, TextBox).Text & "'"
End If

ElseIf TypeOf childCtrl Is DropDownList Then
If childCtrl.ID = CtrName Then 'Or childCtrl.UniqueID = CtrName
getPameterValue = "'" & CType(childCtrl, DropDownList).SelectedItem.Value.ToString & "'"
End If

End If

Next childCtrl

Return getPameterValue
End Function
 
Share this answer
 
Oddly, this just came up as the 'Featured Article[^]' for today! This might be quite helpful.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900