In this article I will explain with an example, how to display (show) JavaScript Alert Message Box from Resource file using C# and VB.Net.
With the help of a Base Class, the ASP.Net Render function will be overridden and the values of the Global and Local Resource files (.resx) will be embedded in JavaScript which later can be used to show JavaScript Alert Message Box in C# and VB.Net.
Creating Base Class for performing Localization in JavaScript
First add a new class named BasePage.cs and place it in the App_Code folder of your ASP.Net website project.
Then you will need to override the Render function to call the Localize function. The Localize function will automatically fetch all the Resource keys placed with braces along with Localize keyword and replace it with its Localized string value from the respective Resource file.
using System;
using System.Web;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
public class BasePage : Page
    protected override void Render(HtmlTextWriter writer)
        StringBuilder sb = new StringBuilder();
        StringWriter sw = new StringWriter(sb);
        HtmlTextWriter hWriter = new HtmlTextWriter(sw);
    private const string ResourceFileName = "Resource";
    private string Localize(string html)
        MatchCollection matches = new Regex(@"Localize\(([^\))]*)\)", RegexOptions.Singleline | RegexOptions.Compiled).Matches(html);
        foreach (System.Text.RegularExpressions.Match match in matches)
            html = html.Replace(match.Value, GetGlobalResourceObject(ResourceFileName, match.Groups[1].Value).ToString());
        return html;
Imports System
Imports System.Web
Imports System.Web.UI
Imports System.Text
Imports System.IO
Imports System.Text.RegularExpressions
Public Class BasePage
    Inherits System.Web.UI.Page
    Private Const ResourceFileName As String = "Resource"
    Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
        Dim sb As StringBuilder = New StringBuilder
        Dim sw As StringWriter = New StringWriter(sb)
        Dim hWriter As HtmlTextWriter = New HtmlTextWriter(sw)
    End Sub
    Private Function Localize(ByVal html As String) As String
        Dim matches As MatchCollection = (New Regex("Localize\(([^\))]*)\)", (RegexOptions.Singleline Or RegexOptions.Compiled)).Matches(html))
        For Each match As System.Text.RegularExpressions.Match In matches
            html = html.Replace(match.Value, GetGlobalResourceObject(ResourceFileName, match.Groups(1).Value).ToString)
        Return html
    End Function
End Class
Note: The name of the resource file in my application is Resource, you need to replace the name of the Resource file where the line is marked in Yellow.
Once you are done with this you are now ready to use it. To make use of this Base class you need to inherit the same in the ASPX Page class.
public partial class _Default : BasePage
Partial Class _Default
    Inherits BasePage
HTML Markup
The following HTML Markup consists of an HTML Button which calls the ShowGreetings JavaScript function when clicked.
Inside the ShowGreetings JavaScript function, the message variable has been assigned with Resource Key value.
This Resource key value will be replaced with the string value from the respective Resource value based on the selected Language.
The value of the variable message is displayed in JavaScript Alert Message Box.
<input id="btnGreetings" type="button" value="Show Greetings" onclick="ShowGreetings()" />
<script type="text/javascript">
        function ShowGreetings() {
            var message = 'Localize(Greetings)';
Resource file
The following is the Resource file for French language. The Resource Key value is wrapped inside the Localize method in your HTML page.
Display (Show) JavaScript Alert Message Box from Resource file in ASP.Net
Display (Show) JavaScript Alert Message Box from Resource file in ASP.Net