Creating Global Variables should be required when working in any programming language.
In Classic ASP, it just worked, but in ASP.NET it didn't. In this article, we will look at both of these Variables that can be used throughout our page.
Place this at the top of your page.
[ASP.NET (VB) - FrontEnd GlobalVariables]
CFFCS |
|
ASP.NET (VB/C#)
Expand
Copy
Download Code
<script runat="server" language="vbscript">
Public Class GlobalVariables
Public Shared strSharedArtistFolderID As String
Public Shared strSharedAlbumFolderID As String
Public Shared FileToMove As String
Public Shared MoveLocation As String
Public Shared MovePath As String
Public Shared getfile As String
End Class
</script>
Now, on our page, we can use either of these variables.
Create your Select Statement. Then add in your Global variable like this.
[ASP.NET (VB) - How to use in FrontEnd]
CFFCS |
|
ASP.NET (VB/C#)
Expand
Copy
Download Code
If drSet.Read () Then
' Feed your GlobalVariables in one single pass
GlobalVariables.getfile = drSet("MyFile")
End If
Now, anywhere on our page, we can use this.
<%=GlobalVariables.getfile%> Will get the value assigned to this Variable.
The same concept will work in the Codebehind as well.
Except without the Code Brackets.
[ASP.NET (VB) - BackEnd GlobalVariables]
CFFCS |
|
ASP.NET (VB/C#)
Expand
Copy
Download Code
Public Class GlobalVariables
Public Shared strSharedArtistFolderID As String
Public Shared strSharedAlbumFolderID As String
Public Shared FileToMove As String
Public Shared MoveLocation As String
Public Shared MovePath As String
Public Shared getfile As String
End Class
And as shown in the FrontEnd, we use the same in the BackEnd.
divwrap=ASP.NET (VB) - How to use in BackEnd]
CFFCS |
|
ASP.NET (VB/C#)
Expand
Copy
Download Code
If drSet.Read () Then
' Feed your GlobalVariables in one single pass
GlobalVariables.getfile = drSet("MyFile")
End If
[/divwrap]
GlobalVariables.getfile