Logo 
Search:

Asp.net Answers

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds
  Question Asked By: Gerritt Bakker   on Jul 22 In Asp.net Category.

  
Question Answered By: Louis Mason   on Jul 22

This .net thing also supports global  static variables in the global.asax
file. You can do this by...


--- global.asax ---
<%@ application  Codebehind="Global.asax.cs" Inherits="TestVBNet.Global"
Classname="CommerceApplication" %>
<Script Language="C#" runat=server>
public static string strPublicString = "yo yo3";
</Script>

--- pagethatwillusetheglobalstaticvariabe.aspx ---
< %@Import <mailto:%@Import> Namespace="System"%>
<%@ page  Language="vb" AutoEventWireup="false" %>
<HTML>
<HEAD>
<SCRIPT runat=server>

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Write(CommerceApplication.strPublicString)
End Sub
</SCRIPT>
</HEAD>
<body>
<form id=frmX runat=server></form>
</body>
</HTML>


You can access the variable  by <ClassName>.<VariableName> -- where
<ClassName> is the value of the Classname attribute in the Application tag
in global.asax. You can also modify that variable - but i think it'll only
be initialized once when the application loads.

Share: 

 

This Question has 8 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Global Variable Or get search suggestion and latest updates.


Tagged: