473,387 Members | 1,321 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,387 software developers and data experts.

Public Functions in Global.asax?

Mat
Hi,

I am trying to create a set of global functions that are available to
any page. However I am not really getting anywhere, even after looking
at several examples.

This is the code I have so far:

(simple.aspx)
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="RealSimple.CodeBehindSimple" src="simple.vb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title></title>
</head>

<body>

<form runat="server">

<asp:Label id="moog" runat="server" />
<asp:Button id="btn_doit" runat="server" OnClick="buttonclick" />

</form>

</body>
</html>

(simple.vb)
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace RealSimple
Public Class CodeBehindSimple
Inherits Page

Protected WithEvents moog As label

Public Sub New()
End Sub
sub buttonclick(s as object, e as eventargs)
moog.text = myGlobal.SayGoodbye("M")
end sub
End Class
End Namespace

(global.asax)
<%@ Application language="VB" Classname="myGlobal" %>
<script runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(Sender As Object, E As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(Sender As Object, E As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(Sender As Object, E As EventArgs)
' Code that runs when a session ends
End Sub
Public Shared Function SayGoodbye( name As String ) As String
Return name
End Function

</script>
The problem is, when try and fire this off (simple.aspx) I get the
following error:
BC30451: Name 'myGlobal' is not declared.
Any ideas what is going wrong?

I have looked at 'http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=708199'
which is what I have based my code on.

I am not using VS, just a simple text editor.

Many thanks,
Mat.
Nov 18 '05 #1
3 3713
Create a Class Library, and use them out of the Class Library.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Mat" <ma*@u2orange.co.uk> wrote in message
news:a7*************************@posting.google.co m...
Hi,

I am trying to create a set of global functions that are available to
any page. However I am not really getting anywhere, even after looking
at several examples.

This is the code I have so far:

(simple.aspx)
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="RealSimple.CodeBehindSimple" src="simple.vb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title></title>
</head>

<body>

<form runat="server">

<asp:Label id="moog" runat="server" />
<asp:Button id="btn_doit" runat="server" OnClick="buttonclick" />

</form>

</body>
</html>

(simple.vb)
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace RealSimple
Public Class CodeBehindSimple
Inherits Page

Protected WithEvents moog As label

Public Sub New()
End Sub
sub buttonclick(s as object, e as eventargs)
moog.text = myGlobal.SayGoodbye("M")
end sub
End Class
End Namespace

(global.asax)
<%@ Application language="VB" Classname="myGlobal" %>
<script runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(Sender As Object, E As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(Sender As Object, E As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(Sender As Object, E As EventArgs)
' Code that runs when a session ends
End Sub
Public Shared Function SayGoodbye( name As String ) As String
Return name
End Function

</script>
The problem is, when try and fire this off (simple.aspx) I get the
following error:
BC30451: Name 'myGlobal' is not declared.
Any ideas what is going wrong?

I have looked at 'http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=708199' which is what I have based my code on.

I am not using VS, just a simple text editor.

Many thanks,
Mat.

Nov 18 '05 #2
I think that is because your class is in one namespace, and myGlobal ends up
being in another.

In any case, I don't recommend you put any function in global other then the
ones it itself will need. Create a brand new class, and put your shared
functions in there.

"Mat" <ma*@u2orange.co.uk> wrote in message
news:a7*************************@posting.google.co m...
Hi,

I am trying to create a set of global functions that are available to
any page. However I am not really getting anywhere, even after looking
at several examples.

This is the code I have so far:

(simple.aspx)
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="RealSimple.CodeBehindSimple" src="simple.vb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title></title>
</head>

<body>

<form runat="server">

<asp:Label id="moog" runat="server" />
<asp:Button id="btn_doit" runat="server" OnClick="buttonclick" />

</form>

</body>
</html>

(simple.vb)
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace RealSimple
Public Class CodeBehindSimple
Inherits Page

Protected WithEvents moog As label

Public Sub New()
End Sub
sub buttonclick(s as object, e as eventargs)
moog.text = myGlobal.SayGoodbye("M")
end sub
End Class
End Namespace

(global.asax)
<%@ Application language="VB" Classname="myGlobal" %>
<script runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(Sender As Object, E As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(Sender As Object, E As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(Sender As Object, E As EventArgs)
' Code that runs when a session ends
End Sub
Public Shared Function SayGoodbye( name As String ) As String
Return name
End Function

</script>
The problem is, when try and fire this off (simple.aspx) I get the
following error:
BC30451: Name 'myGlobal' is not declared.
Any ideas what is going wrong?

I have looked at 'http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=708199' which is what I have based my code on.

I am not using VS, just a simple text editor.

Many thanks,
Mat.

Nov 18 '05 #3
Mat
Cheers, I took your advice and wrote a class. Works like a charm.

Thanks!!!
Mat.

"Marina" <so*****@nospam.com> wrote in message news:<#A**************@TK2MSFTNGP10.phx.gbl>...
I think that is because your class is in one namespace, and myGlobal ends up
being in another.

In any case, I don't recommend you put any function in global other then the
ones it itself will need. Create a brand new class, and put your shared
functions in there.

"Mat" <ma*@u2orange.co.uk> wrote in message
news:a7*************************@posting.google.co m...
Hi,

I am trying to create a set of global functions that are available to
any page. However I am not really getting anywhere, even after looking
at several examples.

This is the code I have so far:

(simple.aspx)
<%@ Page Language="vb" AutoEventWireup="false"
Inherits="RealSimple.CodeBehindSimple" src="simple.vb" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title></title>
</head>

<body>

<form runat="server">

<asp:Label id="moog" runat="server" />
<asp:Button id="btn_doit" runat="server" OnClick="buttonclick" />

</form>

</body>
</html>

(simple.vb)
Imports System
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls

Namespace RealSimple
Public Class CodeBehindSimple
Inherits Page

Protected WithEvents moog As label

Public Sub New()
End Sub
sub buttonclick(s as object, e as eventargs)
moog.text = myGlobal.SayGoodbye("M")
end sub
End Class
End Namespace

(global.asax)
<%@ Application language="VB" Classname="myGlobal" %>
<script runat="server">
Sub Application_Start(Sender As Object, E As EventArgs)
' Code that runs on application startup
End Sub
Sub Application_End(Sender As Object, E As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(Sender As Object, E As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(Sender As Object, E As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(Sender As Object, E As EventArgs)
' Code that runs when a session ends
End Sub
Public Shared Function SayGoodbye( name As String ) As String
Return name
End Function

</script>
The problem is, when try and fire this off (simple.aspx) I get the
following error:
BC30451: Name 'myGlobal' is not declared.
Any ideas what is going wrong?

I have looked at

'http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=708199'
which is what I have based my code on.

I am not using VS, just a simple text editor.

Many thanks,
Mat.

Nov 18 '05 #4

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

Similar topics

2
by: Ekul | last post by:
I have an application that allows users to login and logout. I track how many users are logged in and when each individual is logged in. The application will not allow concurrent logins(let a...
3
by: hansiman | last post by:
I use Application_Start in global.asax to set some physical folder paths ie.: Application("pdf") = "c:\www\<site>\pdf\" global.asax uses code behind. When I move the project from the dev to...
12
by: John M | last post by:
Hello, On Microsoft Visual Studio .NET 2003, I want to use some global elements, that can be used in each one of my pages. i.e I put a oleDBConnection on global.asax.vb How can I use it...
5
by: ad | last post by:
The Global.asax is code-inside with default. How to change Global.asax to code-behind?
11
by: Ron | last post by:
I have a web project compiled with the new "Web Deployment Projects" plugin for VS2005. I'm deploying the web project to one assembly and with updateable option set to ON. When I'm running the...
16
by: thefritz_j | last post by:
We just converted our VS2003 1.1 VB web project (which was working fine) to VS2005 2.0 and now I get: Parser Error Message: Could not load type '<Namespace>.'. Source Error: Line 1: <%@...
5
by: John | last post by:
Hi Is there a way to declare public functions that can be accessed in any aspx page? Can global variables be declared? Thanks Regards
3
by: David | last post by:
Hi, I have seen in some site implementations code has been entered into global.asax.cs in its own function, not any of the regular application or session functions that exist in here. What I...
6
by: stoogots2 | last post by:
am using Visual Studio 2003, .Net Framework 1.1, C#. I get a SystemNullReferenceException when trying to do a hashtable.add(string,string) from a login page, and I do not understand why because all...
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: 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
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
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
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.