473,386 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

reference to web form

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
Nov 18 '05 #1
4 1293
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Tomk" <to****@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
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

Nov 18 '05 #2
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.

"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Tomk" <to****@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
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


Nov 18 '05 #3
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.

"Tomk" <to****@hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
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.

"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Tomk" <to****@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
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



Nov 18 '05 #4
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


"Kevin Spencer" <ke***@takempis.com> wrote in message
news:OF**************@TK2MSFTNGP10.phx.gbl...
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.

"Tomk" <to****@hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
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.

"Chris Jackson" <chrisjATmvpsDOTorgNOSPAM> wrote in message
news:Oi**************@tk2msftngp13.phx.gbl...
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.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Tomk" <to****@hotmail.com> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
>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
>
>



Nov 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Cybertof | last post by:
Hello, What is the difference between : - adding a new reference to a namespace within the SolutionExplorer (right click, Add Reference...) - adding a new reference with the 'using' keyword in...
12
by: Bill Todd | last post by:
Form B needs to call a public method of Form A. How can form B get a reference to the instance of Form A using its name or any other method? Is there a collection of form instances that can be...
1
by: Oney | last post by:
How can I reference a Windows Form In details; I created two Form (frm1,frm2) I want to reach frm1 controls from frm2 in runtime. So I have to reference frm1 by the way there is no mdi form ...
3
by: Giovanni Bassi | last post by:
Hello all, I have prepared a simple procedure to open forms only once. Here it is: -//- Private Sub OpenChildForm(ByRef objFormToOpen As System.Windows.Forms.Form, ByVal TypeToCreate As...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
16
by: Paul S. Natanson | last post by:
What is a Null Reference error and how do I fix it? My newly installed VB.Net2003 gives me a "Microsoft Development Environment" error message box EVERY time I try to run/start ANY project -...
16
by: John | last post by:
Hi I have posted this question several times but have received no reply. I have a main form which contains a panel which in turn contains a child form, like this; MainForm->MyPanel->ChildForm....
3
by: Ann Huxtable | last post by:
I wrote a method that accepted a form. The signature was as ff: void foo(ref Form frm) ; I had to remove the ref keyword to get it to compile. Any idea why? I though forms would be passed by...
10
by: Richard Lewis Haggard | last post by:
I've created in form that has tab controls that contain tab controls that host user controls on each tab page. It compiles and runs just fine but the designer view fails with a "A circular control...
9
by: Brad Pears | last post by:
I have the following code that references a "textbox" on a form. I want to pass the value of this textbox to a stored procedure as a parameter. This code is located on a different form obviously. I...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.