![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
I created a custom web control and placed a couple instances on an aspx page. The idea is that the user needs to make a selection in each control and then click on a button to save the answers in each control to a database. How can I programmatically scroll through all the controls on the page to retrieve the values in each custom control? Here is my best shot which doesn't work, but should give you an idea of what I am trying to do: Private Sub Button1_Click(ByVal sender ....) Handles Button1.Click Dim item As Control For each item in Me.Controls 'Code to check each control to see if we need to save its value. Response.Write(item.ID.ToString & "<br>") Next End Sub. I need to pick up on the control's ID or type... any suggestions on how I can do that? Scott |
#3
| |||
| |||
|
#4
| |||
| |||
|
|
on isPostBack as follows: |
|
Hi Scott, Thanks for posting in this group. Actully, when you add control on the web page, it will be added into the form's control collection, so you should loop through the Form's Controls property. To get the programming interface to form element, you should add a HtmlForm declearation for this form. Do something like this: Protected Form1 As System.Web.UI.HtmlControls.HtmlForm Private Sub Button1_Click(ByVal sender ....) Handles Button1.Click Dim item As Control For each item in Form1.Controls if item is TextBox or item is Button then Response.Write(item.ID.ToString & "<br>") end if Next End Sub. Any HTML tags or text strings that are not processed on the server are treated as LiteralControl objects. These are added to the collection like other server controls. They have no ID properties(null). So you should check the control's type(In the code snippet, I only check TextBox and Button) Hope this helps, Best regards, Jeffrey Tan Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights. |
#5
| |||
| |||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |