F
fd123456
Hi tshad, sorry for not coming back to you earlier.
When I meant to add a method to Global.asax, I actually meant to add
it to the code-behind file. If you click on "Global.asax" in the file
explorer, then on the F7 key, you can edit this code-behind; that's
the one that includes the Application_Start, Application_BeginRequest,
etc, routines (I don't even know where you added the <script> bit).
In this file, you can add your own methods and they should be callable
from anywhere in your code, provided they are Public and Shared.
Your routine in Global should be :
public shared function tom() as string
Return "This is the shared sub"
end function
(although I believe that your version was correct, but I'm not too
good with VB syntax)
and in your test aspx file, it should be :
Sub Page_Load(sender as Object, e as EventArgs)
Response.Write(Global.tom())
End Sub
(actually, once again, I'm not comfortable with VB and it is very
possible that you should omit the "()" after "tom").
Regarding your "MyUtils" attempt, I believe that this helper class
should not inherit from HttpApplication. My guess is that : 1) you
would have two concurrent applications running, not talking to each
other, provided that 2) you had Run that second application, which you
have not. Just don't inherit it from anything, put it in it's own
file, make sure that the NameSpace is the same as the rest of your app
(which should already be the case as you have added the class in your
Global.asax code-behind file) and you should be all set. Oh, and also
check that your MyUtils class is at the same level than the Global()
class, not inside, because then you would have nested classes, which
you would have to call through Global().MyUtils.MyMethod, and the
scope rules are a bit different then.
But once again, you don't *need* to create a class, you can just add
the method to the existing Global ones.
Tell me if you still run into trouble.
Michel
When I meant to add a method to Global.asax, I actually meant to add
it to the code-behind file. If you click on "Global.asax" in the file
explorer, then on the F7 key, you can edit this code-behind; that's
the one that includes the Application_Start, Application_BeginRequest,
etc, routines (I don't even know where you added the <script> bit).
In this file, you can add your own methods and they should be callable
from anywhere in your code, provided they are Public and Shared.
Your routine in Global should be :
public shared function tom() as string
Return "This is the shared sub"
end function
(although I believe that your version was correct, but I'm not too
good with VB syntax)
and in your test aspx file, it should be :
Sub Page_Load(sender as Object, e as EventArgs)
Response.Write(Global.tom())
End Sub
(actually, once again, I'm not comfortable with VB and it is very
possible that you should omit the "()" after "tom").
Regarding your "MyUtils" attempt, I believe that this helper class
should not inherit from HttpApplication. My guess is that : 1) you
would have two concurrent applications running, not talking to each
other, provided that 2) you had Run that second application, which you
have not. Just don't inherit it from anything, put it in it's own
file, make sure that the NameSpace is the same as the rest of your app
(which should already be the case as you have added the class in your
Global.asax code-behind file) and you should be all set. Oh, and also
check that your MyUtils class is at the same level than the Global()
class, not inside, because then you would have nested classes, which
you would have to call through Global().MyUtils.MyMethod, and the
scope rules are a bit different then.
But once again, you don't *need* to create a class, you can just add
the method to the existing Global ones.
Tell me if you still run into trouble.
Michel