By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,458 Members | 1,252 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,458 IT Pros & Developers. It's quick & easy.

Public Functions in Global.asax?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.