M
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.
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.