reference to web form

T

Tomk

I would like to make a routine that I can reuse on all my web forms to loop
thru all webcontrols. However to do this I will need to pass a reference of
the class that is associated with the form but I can't figure out the type
to use in the method paramenter.

something like this:

Public Class myWebForm
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
InitializeComponent()

Dim objCommonRoutine as new myCommonRoutine()
Call objCommonRoutine .DoStuff("Select * From Table", Me)
End Sub
End Class

Public Class myCommonRoutine
Public Sub New()

End Sub

Public Sub DoStuff(ByVal strStuff as String, ByRef objWebForm as ????)
For Each WebControl in objWebForm
bla bla
Next
End Sub
End Class
 
C

Chris Jackson

Web forms are derived from System.Web.UI.Page. However, you'll find your
foreach statement to be inadequate, as you will only get the root level
controls. If you have any container controls (such as a table) their
children will not be iterated through, so you will need to make this call
recursively if you want to get that absolutely everything.

But, if you need to go through everything each time, this is a rather slow
and tedious approach. You may want to consider deriving some custom server
controls that have the properties you need, which will make your application
perform exponentially better.
 
T

Tomk

Thanks for your reply,

What I am looking to do is simplfy the design of forms with lots of
textboxes & dropdownlists. I did this in traditional ASP with an include
file and a function I called populatefields. The populatefields call would
cycle thru all form elements and match control names with database fields.
The texboxes are pretty easy, I just match the name of the textbox with the
column name in the recordset.
 
K

Kevin Spencer

One thing I have learned with regards to ASP.Net is that the best route to
take when redesigning an ASP application for ASP.Net is to forget about how
you did it with ASP. The 2 technologies work in entirely different ways.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
T

Tomk

Keven,

I agree with that thought whole heartedly...so the question remains, how do
I populate the text fields of several web forms without having to explicitly
read & write to each textbox by name. My concept in old ASP was very
eligant and I would like to figure out a way to get this done in .NET
 

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

Top