Reputation:
The name 'Global' does not exist in the current context
I'm getting the above error when trying to reference a property I've created in Global.asax:
public static String ThemeColor
{ get; set; }
from the C# on the aspx page (outputting some javascript):
alert("<%=Global.ThemeColor %>");
Any ideas why?
Upvotes: 0
Views: 2358
Reputation: 2394
If you're putting these sorts of values in Global.asax you need a doctor.
Create a class called "GlobalSiteValues" or whatever. Make sure the namespace it lives in is either the same as the aspx page, or registered in web.config (or non-existent or use the full name).
Then this will work (once you have set the value, obviously)
public class GlobalSiteValues
{
public static string MyString{ get;set }
public static int MyInt{ get;set; }
}
... and in the aspx page (in script block)...
var abc = "<%= GlobalSiteValues.MyString %>";
alert(abc);
Or why not set up a "context class" for your site. Like HttpContext.Current
?
Upvotes: 0
Reputation: 150253
Several options:
Global
, Maybe you changed it?using
of the namespaceYou really should not use the Global.asax
to handle the theme color.
css
seems to be a more appropriate place for it...
Upvotes: 5
Reputation: 10992
Why don't you make a separate class of the theme-color and at the application-start event in global.asax set the themecolor to something.
Upvotes: 0