In this article, I’m explaining about resources in .NET

What is Resources file?

A resources file is a XML file that contains the string that we want to:

a.       Translate into different language.

b.      Can be updated dynamically so that user themselves can modify values in resources files one the application is deployed on the server without re-compiling the entire application itself. 

 c.       The resource file contains key/value pairs.

d.      Each pair is an individual resources.

e.      Key name are not case sensitive.

Types of resources:

1.       Local resources

2.       Global resources 

Local resources: 

  1.       Local resources:

1.       Local resources is specific to a single web page and used for providing version of a web page in different language.

2.       Local resources must be stored in App_LocalResources sub folder.

3.       Local resources must be named in format <WebPageName>[.language/language and culture etc]

4.       Example: Default.aspx.resx- Base resource file.  

2.       Global resources:

1.       Global resource can be read from any  page or code that is  in the application.

2.       Global resource must be stored in App_GlobalResources at the root of the application.


1.       Create a Default.aspx file.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DetailForm.aspx.cs" Inherits="ResourceSam.DetailForm"  Culture="auto" UICulture="auto"%>


<!DOCTYPE html>


<html xmlns="">

<head runat="server">

    <link href="css/bootstrap.css" rel="stylesheet" />




    <form id="form1" runat="server">



            <tr><td>Select language</td><td> <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">

            <asp:ListItem Value="en-us">English</asp:ListItem>

            <asp:ListItem Value="hi-in">हिंदी</asp:ListItem>

  <asp:ListItem Value="Ur">اردو</asp:ListItem>

        </asp:DropDownList><br /></td></tr>


                <td> <asp:Label ID="lblinformation" runat="server" Text="Personal informatiom" meta:resourceKey="lblinformation"></asp:Label></td>






                <td> <asp:Label ID="lblFirstName" runat="server" Text="First Name"  meta:resourceKey="lblFirstName"></asp:Label></td>


                    <asp:TextBox ID="txtFirstName" runat="server"></asp:TextBox></td>



                <td><asp:Label ID="lblLastName" runat="server" Text="Last Name" meta:resourceKey="lblLastName"></asp:Label></td>


                    <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>



                <td><asp:Label ID="lblAge" runat="server" Text="Age" meta:resourceKey="lblAge"></asp:Label></td>


                    <asp:TextBox ID="txtAge" runat="server"></asp:TextBox></td>



                <td colspan="2">

                    <asp:Button ID="btnReg" runat="server" Text="Register" meta:resourceKey="btnReg" /></td>








2.      Write in Default.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Reflection;

using System.Resources;

using System.Globalization;

using System.Threading;

namespace ResourceSam


    public partial class DetailForm : System.Web.UI.Page


        protected void Page_Load(object sender, EventArgs e)




        protected override void InitializeCulture()


            if (Request.Form["DropDownList1"] != null)


                UICulture = Request.Form["DropDownList1"];

                Culture = Request.Form["DropDownList1"];









3.    Right click on application>> select Add Option>>select  Add ASP.NET Folder>>select>>App_LocalResources>>Right click on App_localResouces>> Select Resource file>> 

1.       DetailForm.aspx.resx for English

2.       DetailForm.aspx.hi-in.resx for Hindi     

Resources in .NET

Resources in .NET


Resources in .NET



Resources in .NET

  Modified On Sep-07-2019 12:15:18 AM

Leave Comment