My project contains multiple aspx pages. Many of these pages have
code-behind that use several helper functions.
Instead of copying each helper function into each aspx page, I am
thinking of using a VB Class file to store these.
Questions -
- How would I "include" this class in each aspx page?
- How would I call the functions?
- One of my functions does a "Page.FindControl". How can I make the Page
object accessible within the class file? When I use Page.FindControl in
my VB class file, VS .NET displays an error = "Reference to a non-shared
member requires an object reference". I've imported system.web in the
class file.
Thx.
Bijoy
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it! 13 2185
Bijoy, - How would I "include" this class in each aspx page?
Just create a module in your project. It will be in the assembly, and
automatically "included" (accessible) from all your pages.
- How would I call the functions?
MyModule.MyFunction( arg1, arg2 )
- One of my functions does a "Page.FindControl". How can I make the Page object accessible within the class file
Function MyFunction( pg as Page ) As String
Dim ctrl as Control = pg.FindControl("Blah")
If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It"
End Sub
hope that helps!
--
Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"Bijoy Naick" <b_*****@donoteamil.yahoo.ca> wrote in message
news:ON**************@tk2msftngp13.phx.gbl... My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions.
Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these.
Questions -
- How would I "include" this class in each aspx page?
- How would I call the functions?
- One of my functions does a "Page.FindControl". How can I make the Page object accessible within the class file? When I use Page.FindControl in my VB class file, VS .NET displays an error = "Reference to a non-shared member requires an object reference". I've imported system.web in the class file.
Thx.
Bijoy
*** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:%2*****************@TK2MSFTNGP10.phx.gbl... Bijoy,
- How would I "include" this class in each aspx page? Just create a module in your project. It will be in the assembly, and automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead,
go ahead and create a Public class with Public Shared subs and/or Functions. - How would I call the functions? MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2) - One of my functions does a "Page.FindControl". How can I make the Page object accessible within the class file Function MyFunction( pg as Page ) As String Dim ctrl as Control = pg.FindControl("Blah") If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the whole
page.
--
John Saunders
johnwsaundersiii at hotmail
You can create PageBase class which inherits from web.page and write all functions here..
In aspx page codebehind class inherit this Pageclass..
It is like this
Your PageBAse class:inherits web.page
write all ur functions
end class
ur aspx.vb code behind class
public class urpagename:PageBase
u can refer using base.function name...
end class
"Bijoy Naick" wrote: My project contains multiple aspx pages. Many of these pages have code-behind that use several helper functions.
Instead of copying each helper function into each aspx page, I am thinking of using a VB Class file to store these.
Questions -
- How would I "include" this class in each aspx page?
- How would I call the functions?
- One of my functions does a "Page.FindControl". How can I make the Page object accessible within the class file? When I use Page.FindControl in my VB class file, VS .NET displays an error = "Reference to a non-shared member requires an object reference". I've imported system.web in the class file.
Thx.
Bijoy
*** Sent via Devdex http://www.devdex.com *** Don't just participate in USENET...get rewarded for it!
John,
No reason to recommend against modules. If you look at the compliation, a
Module is created as a public singleton class with all methods static
(shared). Modules are therefore OO. Avoiding them because at one point they
were pre-OO is like avoiding methods from the Microsoft.Visualbasic
namespace (such as Left()) -- it really weakens your toolset as a VB
programmer for no reason.
--
Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:%2*****************@TK2MSFTNGP10.phx.gbl... Bijoy,
- How would I "include" this class in each aspx page? Just create a module in your project. It will be in the assembly, and automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature.
Instead, go ahead and create a Public class with Public Shared subs and/or
Functions. - How would I call the functions? MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
- One of my functions does a "Page.FindControl". How can I make the
Page object accessible within the class file Function MyFunction( pg as Page ) As String Dim ctrl as Control = pg.FindControl("Blah") If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the compliation, a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point
they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no
reason to use modules at all.
--
John Saunders
johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:%2*****************@TK2MSFTNGP10.phx.gbl... Bijoy,
> - How would I "include" this class in each aspx page? Just create a module in your project. It will be in the assembly, and automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead, go ahead and create a Public class with Public Shared subs and/or Functions. > - How would I call the functions? MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
> - One of my functions does a "Page.FindControl". How can I make the Page > object accessible within the class file Function MyFunction( pg as Page ) As String Dim ctrl as Control = pg.FindControl("Blah") If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the compliation, a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point
they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no
reason to use modules at all.
--
John Saunders
johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:%2*****************@TK2MSFTNGP10.phx.gbl... Bijoy,
> - How would I "include" this class in each aspx page? Just create a module in your project. It will be in the assembly, and automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead, go ahead and create a Public class with Public Shared subs and/or Functions. > - How would I call the functions? MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
> - One of my functions does a "Page.FindControl". How can I make the Page > object accessible within the class file Function MyFunction( pg as Page ) As String Dim ctrl as Control = pg.FindControl("Blah") If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
I agree with John. The problem is, most people coming from a VB background
are not familiar with true object-oriented technology, and using a Module is
an easy way for a non-object-oriented developer to create applications
without knowing too much about the new paradigm. Static methods and
properties should be used with great caution, and only where appropriate.
They can be quite problematic. While ASP and VBScript are very forgiving, a
compiled application using the entire CLR as its back end requires a good
bit more discipline than most people coming from a VB background are used
to, and/or willing to employ. IMO, VB.Net is a bit TOO forgiving, under the
circumstances.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:#T**************@TK2MSFTNGP10.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the compliation,
a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no reason to use modules at all. -- John Saunders johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl... > Bijoy, > > > - How would I "include" this class in each aspx page? > Just create a module in your project. It will be in the assembly,
and > automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead, go ahead and create a Public class with Public Shared subs and/or Functions. > > - How would I call the functions? > MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
> > - One of my functions does a "Page.FindControl". How can I make
the Page > > object accessible within the class file > Function MyFunction( pg as Page ) As String > Dim ctrl as Control = pg.FindControl("Blah") > If ctrl Is Nothing Then Return "Where Is It" Else Return "Found
It" > End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
I agree with John. The problem is, most people coming from a VB background
are not familiar with true object-oriented technology, and using a Module is
an easy way for a non-object-oriented developer to create applications
without knowing too much about the new paradigm. Static methods and
properties should be used with great caution, and only where appropriate.
They can be quite problematic. While ASP and VBScript are very forgiving, a
compiled application using the entire CLR as its back end requires a good
bit more discipline than most people coming from a VB background are used
to, and/or willing to employ. IMO, VB.Net is a bit TOO forgiving, under the
circumstances.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:#T**************@TK2MSFTNGP10.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the compliation,
a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no reason to use modules at all. -- John Saunders johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl... > Bijoy, > > > - How would I "include" this class in each aspx page? > Just create a module in your project. It will be in the assembly,
and > automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead, go ahead and create a Public class with Public Shared subs and/or Functions. > > - How would I call the functions? > MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
> > - One of my functions does a "Page.FindControl". How can I make
the Page > > object accessible within the class file > Function MyFunction( pg as Page ) As String > Dim ctrl as Control = pg.FindControl("Blah") > If ctrl Is Nothing Then Return "Where Is It" Else Return "Found
It" > End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
You make a good point. However, when one creates a utility singleton class,
it is generally final (NotInheritable) by design or in practice. Modules are
ideal for utility functions (which I believe the original poster needed).
What's nice about utility functions is you do not need to specify the module
they are in, which is another VB-convience thing.
I'm not advocating using them as part of an enterprise framework, but for
small basic applications (which cover most), they're just an easier path to
the same end.
--
Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the compliation,
a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no reason to use modules at all. -- John Saunders johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in
message news:%2*****************@TK2MSFTNGP10.phx.gbl... > Bijoy, > > > - How would I "include" this class in each aspx page? > Just create a module in your project. It will be in the assembly,
and > automatically "included" (accessible) from all your pages.
I personally recommend against modules, which are a pre-OO feature. Instead, go ahead and create a Public class with Public Shared subs and/or Functions. > > - How would I call the functions? > MyModule.MyFunction( arg1, arg2 )
MyClass.MyFunction(arg1, arg2)
> > - One of my functions does a "Page.FindControl". How can I make
the Page > > object accessible within the class file > Function MyFunction( pg as Page ) As String > Dim ctrl as Control = pg.FindControl("Blah") > If ctrl Is Nothing Then Return "Where Is It" Else Return "Found
It" > End Sub
Pretty good, but if you make the signature be:
Function MyFunction(ctl as Control)
then you'll be able to handle cases where you don't want to search the
whole page. -- John Saunders johnwsaundersiii at hotmail
A bad programmer can abuse any language. I get to see it every day at
TheDailyWTF.com. I don't see how advocating against using a time-saver (a
big part of VB) is going to make any difference in the quality of a product.
"Oh, so I have to call my Modules a 'Class' and add the word 'Shared' to my
Subs. Um, whatever"
--
Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl... I agree with John. The problem is, most people coming from a VB background are not familiar with true object-oriented technology, and using a Module
is an easy way for a non-object-oriented developer to create applications without knowing too much about the new paradigm. Static methods and properties should be used with great caution, and only where appropriate. They can be quite problematic. While ASP and VBScript are very forgiving,
a compiled application using the entire CLR as its back end requires a good bit more discipline than most people coming from a VB background are used to, and/or willing to employ. IMO, VB.Net is a bit TOO forgiving, under
the circumstances.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:#T**************@TK2MSFTNGP10.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:eF**************@TK2MSFTNGP10.phx.gbl... John,
No reason to recommend against modules. If you look at the
compliation, a Module is created as a public singleton class with all methods static (shared). Modules are therefore OO. Avoiding them because at one point they were pre-OO is like avoiding methods from the Microsoft.Visualbasic namespace (such as Left()) -- it really weakens your toolset as a VB programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see no reason to use modules at all. -- John Saunders johnwsaundersiii at hotmail
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:OR**************@TK2MSFTNGP11.phx.gbl... > "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message > news:%2*****************@TK2MSFTNGP10.phx.gbl... > > Bijoy, > > > > > - How would I "include" this class in each aspx page? > > Just create a module in your project. It will be in the assembly, and > > automatically "included" (accessible) from all your pages. > > I personally recommend against modules, which are a pre-OO feature. Instead, > go ahead and create a Public class with Public Shared subs and/or Functions. > > > > - How would I call the functions? > > MyModule.MyFunction( arg1, arg2 ) > > MyClass.MyFunction(arg1, arg2) > > > > - One of my functions does a "Page.FindControl". How can I make the Page > > > object accessible within the class file > > Function MyFunction( pg as Page ) As String > > Dim ctrl as Control = pg.FindControl("Blah") > > If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" > > End Sub > > Pretty good, but if you make the signature be: > > Function MyFunction(ctl as Control) > > then you'll be able to handle cases where you don't want to search
the whole > page. > -- > John Saunders > johnwsaundersiii at hotmail > >
I'd love to know how creating a Module saves time compared to creating a
Class.
--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:O1**************@tk2msftngp13.phx.gbl... A bad programmer can abuse any language. I get to see it every day at TheDailyWTF.com. I don't see how advocating against using a time-saver (a big part of VB) is going to make any difference in the quality of a
product. "Oh, so I have to call my Modules a 'Class' and add the word 'Shared' to
my Subs. Um, whatever"
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"Kevin Spencer" <ks******@takempis.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I agree with John. The problem is, most people coming from a VB
background are not familiar with true object-oriented technology, and using a
Module is an easy way for a non-object-oriented developer to create applications without knowing too much about the new paradigm. Static methods and properties should be used with great caution, and only where
appropriate. They can be quite problematic. While ASP and VBScript are very
forgiving, a compiled application using the entire CLR as its back end requires a
good bit more discipline than most people coming from a VB background are
used to, and/or willing to employ. IMO, VB.Net is a bit TOO forgiving, under the circumstances.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:#T**************@TK2MSFTNGP10.phx.gbl... "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in
message news:eF**************@TK2MSFTNGP10.phx.gbl... > John, > > No reason to recommend against modules. If you look at the compliation, a > Module is created as a public singleton class with all methods
static > (shared). Modules are therefore OO. Avoiding them because at one
point they > were pre-OO is like avoiding methods from the Microsoft.Visualbasic > namespace (such as Left()) -- it really weakens your toolset as a VB > programmer for no reason.
Alex,
Can one inherit from a module? Can one add nonstatic members?
Since a class can do everything a module can do plus far more, I see
no reason to use modules at all. -- John Saunders johnwsaundersiii at hotmail
> -- > Alex Papadimoulis > http://weblogs.asp.net/Alex_Papadimoulis > > > "John Saunders" <jo**************@notcoldmail.com> wrote in message > news:OR**************@TK2MSFTNGP11.phx.gbl... > > "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message > > news:%2*****************@TK2MSFTNGP10.phx.gbl... > > > Bijoy, > > > > > > > - How would I "include" this class in each aspx page? > > > Just create a module in your project. It will be in the
assembly, and > > > automatically "included" (accessible) from all your pages. > > > > I personally recommend against modules, which are a pre-OO
feature. > Instead, > > go ahead and create a Public class with Public Shared subs and/or > Functions. > > > > > > - How would I call the functions? > > > MyModule.MyFunction( arg1, arg2 ) > > > > MyClass.MyFunction(arg1, arg2) > > > > > > - One of my functions does a "Page.FindControl". How can I
make the > Page > > > > object accessible within the class file > > > Function MyFunction( pg as Page ) As String > > > Dim ctrl as Control = pg.FindControl("Blah") > > > If ctrl Is Nothing Then Return "Where Is It" Else Return
"Found It" > > > End Sub > > > > Pretty good, but if you make the signature be: > > > > Function MyFunction(ctl as Control) > > > > then you'll be able to handle cases where you don't want to search the > whole > > page. > > -- > > John Saunders > > johnwsaundersiii at hotmail > > > > > >
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message
news:O1**************@tk2msftngp13.phx.gbl... A bad programmer can abuse any language. I get to see it every day at TheDailyWTF.com. I don't see how advocating against using a time-saver (a big part of VB) is going to make any difference in the quality of a
product. "Oh, so I have to call my Modules a 'Class' and add the word 'Shared' to
my Subs. Um, whatever"
More important is the mindset. A module is just some glob of code. The name
of the module doesn't even matter, since you don't need to specify it!
On the other hand, most of the time, even a simple OO design uses very few
cases of public-class-with-only-public-static-members. If those methods have
something in common, then they probably have a class in common, and should
be members of that class.
Really, once you get the hang of it (or once you're taught properly), OO is
just much more natural. In this case, you won't wind up creating some
"Module" which has to do things _to_ various objects, from the outside.
Instead you'll create public methods which do something _with_ the object to
which they belong.
--
John Saunders
johnwsaundersiii at hotmail
Utility.StripHtml() .... StripHtml() ... hmmm ... well ...
Okay. So it doesn't save any significant time. But neither does Left(s,4) vs
s.SubString(0,4) ... I suppose my point is that it's all part of the VB
toolbox. One thing that's nice (debatably?) about VB is that someone without
much background can very easily create a quick & dirty application. You
don't need to make business classes or anything like that if you just have a
simple webpage that loads and saves stuff from a database. And a Module is a
the perfect fit for helper functions to the little web page.
On the subject ... C# folks now (2.0) get a "module" of their own by
allowing classes to be declared static.
--
Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:OC**************@TK2MSFTNGP11.phx.gbl... I'd love to know how creating a Module saves time compared to creating a Class.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message news:O1**************@tk2msftngp13.phx.gbl... A bad programmer can abuse any language. I get to see it every day at TheDailyWTF.com. I don't see how advocating against using a time-saver
(a big part of VB) is going to make any difference in the quality of a product. "Oh, so I have to call my Modules a 'Class' and add the word 'Shared' to
my Subs. Um, whatever"
-- Alex Papadimoulis http://weblogs.asp.net/Alex_Papadimoulis
"Kevin Spencer" <ks******@takempis.com> wrote in message news:%2****************@TK2MSFTNGP11.phx.gbl... I agree with John. The problem is, most people coming from a VB background are not familiar with true object-oriented technology, and using a Module is an easy way for a non-object-oriented developer to create applications without knowing too much about the new paradigm. Static methods and properties should be used with great caution, and only where appropriate. They can be quite problematic. While ASP and VBScript are very forgiving, a compiled application using the entire CLR as its back end requires a good bit more discipline than most people coming from a VB background are used to, and/or willing to employ. IMO, VB.Net is a bit TOO forgiving,
under the circumstances.
-- HTH, Kevin Spencer .Net Developer Microsoft MVP Big things are made up of lots of little things.
"John Saunders" <jo**************@notcoldmail.com> wrote in message news:#T**************@TK2MSFTNGP10.phx.gbl... > "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message > news:eF**************@TK2MSFTNGP10.phx.gbl... > > John, > > > > No reason to recommend against modules. If you look at the compliation, a > > Module is created as a public singleton class with all methods static > > (shared). Modules are therefore OO. Avoiding them because at one point > they > > were pre-OO is like avoiding methods from the
Microsoft.Visualbasic > > namespace (such as Left()) -- it really weakens your toolset as a
VB > > programmer for no reason. > > Alex, > > Can one inherit from a module? Can one add nonstatic members? > > Since a class can do everything a module can do plus far more, I see no > reason to use modules at all. > -- > John Saunders > johnwsaundersiii at hotmail > > > > -- > > Alex Papadimoulis > > http://weblogs.asp.net/Alex_Papadimoulis > > > > > > "John Saunders" <jo**************@notcoldmail.com> wrote in
message > > news:OR**************@TK2MSFTNGP11.phx.gbl... > > > "Alex Papadimoulis" <al**********@pa3.14padimoulis.com> wrote in message > > > news:%2*****************@TK2MSFTNGP10.phx.gbl... > > > > Bijoy, > > > > > > > > > - How would I "include" this class in each aspx page? > > > > Just create a module in your project. It will be in the assembly, and > > > > automatically "included" (accessible) from all your pages. > > > > > > I personally recommend against modules, which are a pre-OO feature. > > Instead, > > > go ahead and create a Public class with Public Shared subs
and/or > > Functions. > > > > > > > > - How would I call the functions? > > > > MyModule.MyFunction( arg1, arg2 ) > > > > > > MyClass.MyFunction(arg1, arg2) > > > > > > > > - One of my functions does a "Page.FindControl". How can I make the > > Page > > > > > object accessible within the class file > > > > Function MyFunction( pg as Page ) As String > > > > Dim ctrl as Control = pg.FindControl("Blah") > > > > If ctrl Is Nothing Then Return "Where Is It" Else Return "Found It" > > > > End Sub > > > > > > Pretty good, but if you make the signature be: > > > > > > Function MyFunction(ctl as Control) > > > > > > then you'll be able to handle cases where you don't want to
search the > > whole > > > page. > > > -- > > > John Saunders > > > johnwsaundersiii at hotmail > > > > > > > > > > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: anonieko |
last post by:
>
>
>
>
Writing an XML document the .Net way
If you've been using the .Net Framework for even a week, you know that
the kids in Redmond really thought of almost everything, so they're not...
|
by: Gregory A Greenman |
last post by:
I'm trying to write a program in vb.net to automate filling out a
series of forms on a website. There are three forms I need to
fill out in sequence. The first one is urlencoded. My program is...
|
by: nevets2001uk |
last post by:
Hi. I've just started my second ASP.NET (VB) app and I'm using
codebehind this time.
I'm not using visual studio but am instead coding it all in notepad
(HTML, ASP.NET and CSS)
I'm trying to...
|
by: Nathan |
last post by:
I have an aspx page with a data grid, some textboxes, and an update button.
This page also has one html input element with type=file (not inside the data
grid and runat=server).
The update...
|
by: Joe Fallon |
last post by:
I would like to know how you can figure out how much memory a given instance
of a class is using.
For example, if I load a collection class with 10 items it might use 1KB,
and if I load it with...
|
by: Joe |
last post by:
Hello All:
Do I have to use the LoadControl method of the Page to load a UserControl?
I have a class which contains three methods (one public and two private).
The class acts as a control...
|
by: rn5a |
last post by:
Using VBC, I compiled a VB class file into a DLL named MyPro.dll. The
namespace used in this class file is 'MyPro' & the public class is
named 'MyClass'. This is the ASPX page which imports the...
|
by: Hexman |
last post by:
Hello All,
I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm
using some VB6 code, .Net2003 code,...
|
by: soms2m |
last post by:
HELLO ALL,
I want to fill the parent window height with respect to the sub window height which is loading using ajax (mootools).
For example if the parent window height is normal and the loading...
|
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,...
|
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$) {
}
...
|
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...
|
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...
|
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...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
| |