Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1061685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:30:36+00:00 2026-05-16T18:30:36+00:00

I want to use global resource in my javascript code. Normally, when the code

  • 0

I want to use global resource in my javascript code. Normally, when the code is inside the ASP code, I use
<%=GetGlobalResourceObject("Resource", "MONTHS_SHORT1") %>
and it works. But, when the javascript code is not inside the ASP code, for example in a folder as calendar.js, it does not work. How can I use the global resource in this case? Note: The resource file is inside my App_GlobalResources folder.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:30:37+00:00Added an answer on May 16, 2026 at 6:30 pm

    Look at the following post I created describing how you can serialise global and local resources and retrieve them from javascript using jQuery and JSON.

    http://bloggingdotnet.blogspot.com/2010_02_01_archive.html

    Firstly, create a new handler (.ashx) file. This one was written quite some time ago, so uses vb.net and custom JSON serialisation:

    Imports System.Web
    Imports System.Web.Services
    Imports System.Xml
    Imports System.Resources
    Imports System.Reflection
    
    Public Class Localisation
      Implements System.Web.IHttpHandler
    
      Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        Dim files As String = context.Request.QueryString("files")
        Dim local As String = context.Request.QueryString("local")
        Dim isLocal As Boolean
        Dim folder As String = "App_GlobalResources"
    
        context.Response.ContentType = "text/javascript"
    
        'Write out file as object
        context.Response.Write("{")
    
        'Determine if local resource file
        If local IsNot Nothing Then
          isLocal = CBool(local)
          If isLocal Then folder = "App_LocalResources"
        End If
        If files Is Nothing OrElse files.Length = 0 Then Throw New ArgumentException("Parameter 'files' was not provided in querystring.")
    
        Dim flag As Boolean = False
        For Each file As String In files.Split(",")
          If flag Then context.Response.Write(",")
    
          Dim className As String = file.Split(".")(0)
    
          'Write the class (name of the without any extensions) as the object
          context.Response.Write(className)
          context.Response.Write(":{")
    
          'Open the resx xml file
          Dim filePath As String = context.Server.MapPath("~\" & folder & "\" & file)
          Dim document As New XmlDocument()
          Dim flag2 As Boolean = False
          document.Load(filePath)
    
          Dim nodes As XmlNodeList = document.SelectNodes("//data")
    
          For Each node As XmlNode In nodes
    
            'Write out the comma seperator
            If flag2 Then context.Response.Write(",")
    
            Dim attr As XmlAttribute = node.Attributes("name")
            Dim resourceKey As String = attr.Value
            context.Response.Write(resourceKey)
            context.Response.Write(":""")
    
            'Write either the local or global value
            If isLocal Then
            context.Response.Write(HttpContext.GetLocalResourceObject(String.Format("~/{0}",    file.Replace(".resx", "")), resourceKey)) 'Has to be full path to the .aspx page
            Else
              context.Response.Write(HttpContext.GetGlobalResourceObject(className, resourceKey))
            End If
            context.Response.Write("""")
    
            'Flag that we need a comma seperator
            flag2 = True
          Next
    
          context.Response.Write("}")
          flag = True
        Next
    
        'End file
        context.Response.Write("}")
      End Sub
    
      Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
          Return True
        End Get
      End Property
    End Class
    

    When that is working, use the following jQuery code to make an ajax call to the http handler and return the contents of the resource file as an object literal.

    // -- Localisation --
    var localResources;
    var globalResources;
    
    //Sample JSON for javascript resource values eg {TrackDetail:{HideHelp:"Hide Help", ShowHelp:"Show Help"}}
    //Usage e.g: alert(localResources.TrackDetail.HideHelp);
    
    //Load Localisation values into variables so that they can be available on the client
    //Note that these values are loaded asynchronously, the code in the function will not run until the call has completed.
    $.getJSON('Localisation.ashx?files=TrackDetail.aspx.resx&local=true', function(data) { localResources = data});
    $.getJSON('Localisation.ashx?files=Errors.resx,Strings.resx', function(data) { globalResources = data});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use resource bundle in login page using tag <spring:message code=login.name />
I want to use a global variable in inline assembly. asm( LDR R0,g_TsInitStackPointerAddress); Here
I am trying to use variable in different function, I want to set global
I want use this 1 for using Bar code or QR code scanner. I
I want use BYTE_ORDER macro in my Xcode project but i can't because i
I want use javascript setInterval function to achieve a box rotate animate effect, I
I want use JQuery mobile for the front-end of my mobile application, but I
I want to use a global variable for using as argument for two or
I am using xslt1.0.I want to use a global variable such a way that,
I want to use a global Style in WP7, something like: <Style TargetType=Button> //some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.