| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
.NET Static VariablesBetter than Application!
<%@ Application Classname="MyGlobals" %>
Then, we specify our Static Variable inside the script tags, using the 'Public' and 'Shared' keywords in the Global.asax: VB: <Script language="vb" runat="server"> Public Shared sGreeting as String = "Visit HarrisonLogic.com!" </Script> C# <Script language="C#" runat="server"> Public Static String sGreeting = "Visit HarrisonLogic.com!" </Script> Now that we have the variable 'sGreeting' set up, we can call it directly from our .aspx page using the Classname and the Variable name: x = MyGlobals.sGreeting Give it a shot! The source code is below: [bold]Page1.aspx[/bold] <% @Page Language="VB" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <script Language='vb' runat=server> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label1.Text = MyGlobals.sGreeting End Sub </script> </HEAD> <body> <asp:label runat=server id=Label1></asp:label> </body> </HTML> [bold]Global.asax[/bold] <%@ Application Classname="MyGlobals" %> <Script language="vb" runat="server"> Public Shared sGreeting as String = "Visit HarrisonLogic.com!" </Script> Read Complete Article |
![]() |
| Viewing: ASP Free Forums > Programming > Code Bank > .NET Static VariablesBetter than Application! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|