473,406 Members | 2,698 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,406 software developers and data experts.

public functions

I need to write a global function that I could use in every page codebehind
and every control. I've created a component (page_base.vb) that contains
the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am then
able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested function
from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the
HostRequested function. I cannot change the 'Inherits' tag because controls
inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?
Nov 18 '05 #1
9 1182
How about putting your function in the Global.aspx.vb file?
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page codebehind and every control. I've created a component (page_base.vb) that contains
the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am then able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested function from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the
HostRequested function. I cannot change the 'Inherits' tag because controls inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?

Nov 18 '05 #2
23s
A control should be able to refernce it's parent page, which (and here's
where I start making this up) you might be able to Ctype() into a Page_Base
and then access the HostRequested function from the resulting object, which
should be a base_page?

Ctype(Me.Page, page_base).HostRequested()

Or just keep all this business at the application level in global.asax I
guess.

"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page codebehind and every control. I've created a component (page_base.vb) that contains
the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am then able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested function from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the
HostRequested function. I cannot change the 'Inherits' tag because controls inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?

Nov 18 '05 #3
put it in a page then inherit from this page for all your others.

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page codebehind and every control. I've created a component (page_base.vb) that contains
the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am then able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested function from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the
HostRequested function. I cannot change the 'Inherits' tag because controls inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?

Nov 18 '05 #4
I just tried this but get "Reference to a non-shared member requires an
object reference."

I am calling the function as "Global.HostRequested()", which is the same
error warning I was getting before when I was calling it as
"Page_Base.HostRequested()". Without the class prefix on the function call
the warning says "Name 'HostRequested' is not declared."
"Scott M." <s-***@nospam.nospam> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl...
How about putting your function in the Global.aspx.vb file?
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page

codebehind
and every control. I've created a component (page_base.vb) that contains the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am

then
able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested

function
from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the HostRequested function. I cannot change the 'Inherits' tag because

controls
inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?


Nov 18 '05 #5
Congratulations! This one worked!
"23s" <as**@asdf.com> wrote in message
news:j8********************@speakeasy.net...
A control should be able to refernce it's parent page, which (and here's
where I start making this up) you might be able to Ctype() into a Page_Base and then access the HostRequested function from the resulting object, which should be a base_page?

Ctype(Me.Page, page_base).HostRequested()

Or just keep all this business at the application level in global.asax I
guess.

"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page

codebehind
and every control. I've created a component (page_base.vb) that contains the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am

then
able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested

function
from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the HostRequested function. I cannot change the 'Inherits' tag because

controls
inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?


Nov 18 '05 #6
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page codebehind and every control. I've created a component (page_base.vb) that contains
the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am then able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested function from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the
HostRequested function. I cannot change the 'Inherits' tag because controls inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.


If you need this method to be accessible both to pages and to controls, then
it does not belong in Page_Base. It should be a Shared method, perhaps in
the Global.asax.vb file. You could then refer to Global.HostRequested().

Note that you'd have to change it as follows:
Public Shared Function HostRequested() As String
HostRequested = HttpContext.Current.Request.URL.Host
End Function

--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #7
Keyword missing was "Shared". Thanks.

BTW, why wouldn't I want to put it in Page_Base? Is there a performance
hit, or difference in how things are cached or compiled??

"John Saunders" <jo**************@notcoldmail.com> wrote in message
news:ui**************@tk2msftngp13.phx.gbl...
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page codebehind
and every control. I've created a component (page_base.vb) that contains the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits
System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am

then
able to add onto the Page_Load procedure in the codebehind for any page
specific functionality. I am also able to access the HostRequested

function
from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to
controls that I am creating. The controls, however, cannot recognize the HostRequested function. I cannot change the 'Inherits' tag because

controls
inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.


If you need this method to be accessible both to pages and to controls,

then it does not belong in Page_Base. It should be a Shared method, perhaps in
the Global.asax.vb file. You could then refer to Global.HostRequested().

Note that you'd have to change it as follows:
Public Shared Function HostRequested() As String
HostRequested = HttpContext.Current.Request.URL.Host
End Function

--
John Saunders
johnwsaundersiii at hotmail

Nov 18 '05 #8
Have you tried marking the function as "Shared"?
"Random" <ci*******@hotmail.com> wrote in message
news:Op**************@TK2MSFTNGP10.phx.gbl...
I just tried this but get "Reference to a non-shared member requires an
object reference."

I am calling the function as "Global.HostRequested()", which is the same
error warning I was getting before when I was calling it as
"Page_Base.HostRequested()". Without the class prefix on the function call the warning says "Name 'HostRequested' is not declared."
"Scott M." <s-***@nospam.nospam> wrote in message
news:em**************@TK2MSFTNGP11.phx.gbl...
How about putting your function in the Global.aspx.vb file?
"Random" <ci*******@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I need to write a global function that I could use in every page

codebehind
and every control. I've created a component (page_base.vb) that contains the class Page_Base...

Public Class Page_Base
Inherits System.Web.UI.Page

Sub Page_Load(...)
(script that runs on every page)
End Sub

Public Function HostRequested() As String
HostRequested = Request.URL.Host
End Function

End Class

I am able to reference this on every page by substituting the "Inherits System.Web.UI.Page" in the codebehind with "Inherits Page_Base". I am

then
able to add onto the Page_Load procedure in the codebehind for any page specific functionality. I am also able to access the HostRequested

function
from the codebehind

So far so good....

Now I want to extend the accessibility to the HostRequested function to controls that I am creating. The controls, however, cannot recognize the HostRequested function. I cannot change the 'Inherits' tag because

controls
inherit from the System.Web.UI.UserControl class instead of the
System.Web.UI.Page class.

How can I make my HostRequested function accessible from both page
codebehind and controls?



Nov 18 '05 #9
"Random" <ci*******@hotmail.com> wrote in message
news:el****************@TK2MSFTNGP09.phx.gbl...
Keyword missing was "Shared". Thanks.

BTW, why wouldn't I want to put it in Page_Base? Is there a performance
hit, or difference in how things are cached or compiled??


Because you need it to be accessed both from controls and pages.
--
John Saunders
johnwsaundersiii at hotmail
Nov 18 '05 #10

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

Similar topics

1
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking aftwerwards with ILDASM at what is visible in those assemblies from a...
6
by: Chris Mantoulidis | last post by:
Forgive me if I'm wrong but I think there is something like an extra member scope in classes. for example: class abc { ostream & operator << (ostream &, const abc &); istream & operator >>...
3
by: quo | last post by:
two questions: 1) Does this program demonstrate the basic difference between public and private access? It appears correct to say that instances of a class cannot directly call a private...
19
by: qazmlp | last post by:
class base { // other members public: virtual ~base() { } virtual void virtualMethod1()=0 ; virtual void virtualMethod2()=0 ; virtual void virtualMethod3()=0 ;
9
by: Banaticus Bart | last post by:
I wrote an abstract base class from which I've derived a few other classes. I'd like to create a base class array where each element is an instance of a derived object. I can create a base class...
4
by: Gianni Mariani | last post by:
I need to store some sensitive data and I want to use public keys so anyone can encrypt the data but can only be decrupted by certain users. Anyhow, are there any loadable modules that do public...
2
by: Bob Rock | last post by:
Hello, in the last few days I've made my first few attempts at creating mixed C++ managed-unmanaged assemblies and looking afterwards with ILDASM at what is visible in those assemblies from a...
9
by: PengYu.UT | last post by:
Suppose I have class A, which defines a lot of member functions a1 ... an. The class B publically inherent from A, because it want to use A's member function. But B only want make member...
86
by: jopperdepopper | last post by:
Hi, finally giving php 5 a go, and going over the new approach to classes. Can someone clarify the public, private and protected to me? I quote the php manual: "The visibility of a property or...
23
by: Chris Gordon-Smith | last post by:
Hello All I have a base class called Action_Request, and a set of classes corresponding to different kinds of Action_Request, each of which inherits from Action_Request. Eg:- class ...
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: 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: 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...
0
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
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,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.