Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: Global Procedures?


Message #1 by "Dogers" <dogers@t...> on Mon, 22 Apr 2002 22:36:47 +0100
What would be the best way to store and call global procedures? In
traditional asp, I had them in a file, functions.inc which was called by
<!-- #include file="includes/functions.inc" --> which allowed me to call
the functions as if they were written on that page..

Is it possible to do this in asp.net? So far ive found I can store the
database connection string in another file, which then needs to be
included in the html section by way of <dba:connect
id="ctlConnectStrings" runat="server"/> and can then be called in the
code via "strConnect = ctlConnectStrings.JetConnectionString"
Surely theres a better way to do this?

-- 
Dogers

Message #2 by "Minh T. Nguyen" <nguyentriminh@y...> on Tue, 23 Apr 2002 09:19:22 -0700
James,

	I have stored global variables in the global.asax.cs as
followed:

	In your global.asax.cs use something like this:
	<%@ Application Codebehind="Global.asax.cs" Inherits="..."
Classname="FooBar" %>

	If you give your application a class name, you can refer to it
from all your other code behind files as in:

	FooBar.MyVariable (provided that MyVariable is publicly defined
as a static variable in Global.asax.cs).

	Maybe you can do something similar with your methods. Again, in
all the other files, you do not have to inherit from Global or anything.
I wouldn't be surprised if you define a public static method in
Global.asax.cs, you can refer to it in other files. I haven't tried that
out myself, but hey, let us know if this works.

Minh.

-----Original Message-----
From: Dogers [mailto:dogers@t...] 
Sent: Monday, April 22, 2002 2:37 PM
To: ASP+
Subject: [aspx] Global Procedures?


What would be the best way to store and call global procedures? In
traditional asp, I had them in a file, functions.inc which was called by
<!-- #include file="includes/functions.inc" --> which allowed me to call
the functions as if they were written on that page..

Is it possible to do this in asp.net? So far ive found I can store the
database connection string in another file, which then needs to be
included in the html section by way of <dba:connect
id="ctlConnectStrings" runat="server"/> and can then be called in the
code via "strConnect = ctlConnectStrings.JetConnectionString"
Surely theres a better way to do this?

-- 
Dogers



Message #3 by "Peter Lawrence" <peter.lawrence@p...> on Tue, 23 Apr 2002 19:02:28 +0100
I have something similar (without using code behind) to access static
variables.

In global.asax:
<%@ Application Classname="PXO" %>
Public Shared strConRead as String    ' where we save connection string

Then they can be referred to from any .aspx as:
PXO.strConRead

I did some rough speed testing, and accessing static variables was
definitely the fastest (then Cache variables, Application variables, config
values read from web.config (much slower), then database access (orders of
magnitude slower)).

Peter

----- Original Message -----
From: "Minh T. Nguyen" <nguyentriminh@y...>
To: "ASP+" <aspx@p...>
Sent: Tuesday, April 23, 2002 5:19 PM
Subject: [aspx] RE: Global Procedures?


> James,
>
> I have stored global variables in the global.asax.cs as
> followed:
>
> In your global.asax.cs use something like this:
> <%@ Application Codebehind="Global.asax.cs" Inherits="..."
> Classname="FooBar" %>
>
> If you give your application a class name, you can refer to it
> from all your other code behind files as in:
>
> FooBar.MyVariable (provided that MyVariable is publicly defined
> as a static variable in Global.asax.cs).
>
> Maybe you can do something similar with your methods. Again, in
> all the other files, you do not have to inherit from Global or anything.
> I wouldn't be surprised if you define a public static method in
> Global.asax.cs, you can refer to it in other files. I haven't tried that
> out myself, but hey, let us know if this works.
>
> Minh.
>
> -----Original Message-----
> From: Dogers [mailto:dogers@t...]
> Sent: Monday, April 22, 2002 2:37 PM
> To: ASP+
> Subject: [aspx] Global Procedures?
>
>
> What would be the best way to store and call global procedures? In
> traditional asp, I had them in a file, functions.inc which was called by
> <!-- #include file="includes/functions.inc" --> which allowed me to call
> the functions as if they were written on that page..
>


Message #4 by "Dogers" <dogers@t...> on Tue, 23 Apr 2002 21:24:53 +0100
> 	I have stored global variables in the global.asax.cs as
> followed:

Thanks for the info, but global variables I pretty much have figured
(albeit in a different way), its functions/procedures that im really
after storing globally..
Ideally id like to store the page headeras a proc so that extra
headers/stylesheets can be easily added in.

-- 
Dogers

Message #5 by "Minh T. Nguyen" <nguyentriminh@y...> on Tue, 23 Apr 2002 13:22:41 -0700
Dogers,

	Well, if I can store global variables, I would think that you
can store global procedures in very same way. Just read my post again
and do the same thing as global static methods instead of variables.
Both methods and variables are members and not so much different.
	Let me know, if it doesn't work, and I will try to do that
tonight. I really think that it should work.

Minh.

-----Original Message-----
From: Dogers [mailto:dogers@t...] 
Sent: Tuesday, April 23, 2002 1:25 PM
To: ASP+
Subject: [aspx] RE: Global Procedures?


> 	I have stored global variables in the global.asax.cs as
> followed:

Thanks for the info, but global variables I pretty much have figured
(albeit in a different way), its functions/procedures that im really
after storing globally..
Ideally id like to store the page headeras a proc so that extra
headers/stylesheets can be easily added in.

-- 
Dogers



Message #6 by "Dogers" <dogers@t...> on Wed, 24 Apr 2002 14:34:37 +0100
> 	Well, if I can store global variables, I would think 
> that you can store global procedures in very same way. Just 
> read my post again and do the same thing as global static 
> methods instead of variables. Both methods and variables are 
> members and not so much different.
> 	Let me know, if it doesn't work, and I will try to do 
> that tonight. I really think that it should work.

I'll certainly give it a go, but ill have to get back to you in a couple
of days on it.. My degree course deadlines are practically here!
-- 
Dogers


  Return to Index