Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

vb.net clas help

2 views
Skip to first unread message

paulbearden

unread,
Jan 26, 2007, 10:55:41 PM1/26/07
to
Greetings,

I'm fairly new to .net (especially 2.0). I using vb.net, 2.0 framework and
Visual Studio 2005.

I'm trying to create a class with a member that will iterate through a web
page and discover all the controls on the page, list their types, names and
what value they hold. What I want is to be able to save all the fields on
any page without having to know what fields there are to begin with. I'll
then save the fields and values to a collection for later retrieval.

Ultimately I want to create a class that can iterate through all the pages
on the site calling the page class for each page so all the controls on the
entire site can be saved and retrieved.

This will allow me to, for instance, to set the value of a contol three
pages back without having to pass variables or get/set a bunch of sessions.
I will also allow me to enable/disable controls site wide or page wide from
anywhere on the site.

When I attempt to 'discover' what controls are on a given page I have
managed to determine the control types but not their names.

Can anyone provide an example or point me to where I might find one?
Thanks!


chieko

unread,
Feb 26, 2007, 3:19:10 PM2/26/07
to
Paul,
I have half of your answer and I'm still trying to figure out how to get to
the page myself. it turns out that the html control is a child control of the
parent controls. I found the information at :
http://msdn2.microsoft.com/en-us/library/ms178509(VS.80).aspx


' loop through the controls on the page.
Dim c As Control
Dim child As Control
Dim txtbox As TextBox
Dim ddl As DropDownList
Dim returnvalue As Type
For Each c In page.Controls
If c.Controls.Count > 0 And c.Controls.GetType.ToString =
"System.web.ui.HtmlControls.htmlform" Then
For Each child In c.Controls
If child.GetType.ToString = "System.web.ui.webcontrols.textbox" Then
txtbox = CType(child, TextBox)
' no blanks allowed.
If txtbox.Text.Equals("") Then
txtbox.BackColor = Color.Magenta
txtbox.Text = "required."
End If
End If

If child.GetType.ToString =
"System.web.ui.webcontrols.dropdownList" Then
ddl = CType(child, DropDownList)
' no blanks allowed.
If ddl.SelectedValue.Equals("") Then
ddl.BackColor = Magenta
End If
End If


Next
End If
Next

chieko

unread,
Feb 28, 2007, 9:28:58 AM2/28/07
to
I found the second half of your question but I haven't tried it yet.
Chieko
In your class create a function something like this:
Public Function Validation(ByRef myPage As Page) As Boolean
Dim bRet As Boolean = True

' Loop page Or form If Error Do what you have To Do And Set bRet=False

Return bRet
End Function


In the webform or webform codebehind page in the submit click event enter
something like this:
If myClass.Validation(Me)=True Then
' No Error call save Function
Else
' An Error has occurred return To form displaying list of errors
End If

0 new messages