How to Implement Global resources concepts in asp.net web applications using Explicit Localization Expression

By
Hi Friend, I have already explained, How to use local resources in asp.net web applications using implicit localization Expression. Today, we will learn about Global resources in asp.net web applications.This localization expressions are automatically generated when resources are created using explicit loalization.You need to use explicit localization in asp.net web pages to localize large text messages,in addition to the controls and labels that are localized.
There are some steps to implement this whole concepts as given below:-
Step 1 :- First Open Your Visual studio -->File-->New -->Web Site--> Select ASP.NET Empty Website --> OK--> Open Solution Explorer window--> Add a New Page (Default.aspx)-->Right-click on Project -->select Add ASP.NET Folder-->Press  App_GlobalResources as shown below:-


Step 2 :- Now Right-click the App_GlobalResources option from the context menu --> Add New Items...--> Select Resource File-->Write Resource file Name =  Default.resx --> Press Add Button as shown below:-
Step 3 :-Similarly, Add Two another files Default.fr.resx and Default.ur.resx as shown below:-

Note- You can Add other countries files also according to your requirements.
Step 4 :- Now Double-click on Default.resx file--> Write the Name =msdotnet and Value=Data Displayed in English Language as shown below:-

Step 5 :- Now Double-click on Default.fr.resx file--> Write the  Name =msdotnet  and Value=Data Displayed in French Language as shown below:-
Step 6 :- Now Double-click on Default.ur.resx file--> Write the  Name =msdotnet  and Value=Data Displayed in Urdu Language as shown below:-

Step 7 :- Now Open Default.aspx page from the Solution Explorer Window--> Add Three Labels and Calendar controls on the page from the Toolbox as shown below:-
Step 8 :- Now Go Properties of Label1 control-->Press (Expressions)--> Select Expression Type = Resources --> Put ResourceKey=msdotnet and ClassKey  =  Default as shown below:-
Note :- This Label control displays the text of languages,whose resource file is loaded in the application. 
Step 9 :-Now open Default.aspx.cs page--> Press F7 and write the C# Codes as given below-

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Threading;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(Request.UserLanguages[0]);
        Label2.Text = "You have selected Date is:=" + Calendar1.SelectedDate.ToShortDateString();
        Label3.Text = "Your System current date and time is =" + System.DateTime.Today.ToLongDateString();
    }
}

Step 10 :- HTML Codes of Default.aspx page as given below:-

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" culture="auto" meta:resourcekey="PageResource1" uiculture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Global Resorces</title>
    <style type="text/css">
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <span class="style3">Welcome To MY.NET Tutorials</span><br class="style3" />
        <table class="style1">
            <tr>
                <td class="style2">
        <asp:Label ID="Label1" runat="server" Text="<%$ Resources:Default, msdotnet %>" 
            style="color: #FF0000; font-weight: 700; font-size: large; background-color: #CCFFFF;"></asp:Label>
        <asp:Calendar ID="Calendar1" runat="server" BackColor="White" 
      BorderColor="Black" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" 
      Height="250px"
   NextPrevFormat="ShortMonth" Width="330px" BorderStyle="Solid" CellSpacing="1" style="font-weight: 700">
   <SelectedDayStyle BackColor="#333399" ForeColor="White" />
   <TodayDayStyle BackColor="#999999" ForeColor="White" />
   <OtherMonthDayStyle ForeColor="#999999" />
   <DayStyle BackColor="#CCCCCC" />
   <NextPrevStyle Font-Bold="True" Font-Size="8pt" ForeColor="White" />
   <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" 
                Height="8pt" />
   <TitleStyle BackColor="#333399" Font-Bold="True"
   Font-Size="12pt" ForeColor="White" BorderStyle="Solid" Height="12pt" />
   </asp:Calendar>
                </td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Label ID="Label2" runat="server" 
                        style="font-weight: 700; color: #FF3300; background-color: #FFFF99" 
                        Text="Label"></asp:Label>
                    <asp:Label ID="Label3" runat="server" 
                        style="color: #0000FF; background-color: #FFCCFF" Text="Label"></asp:Label>
                    </td>
            </tr>
        </table>  
    </div>
    </form>
</body>
</html>
Step 11 :- Now you need to change the Browser settings, When you change the Browser settings then the desired language is displayed in your application when application is executed.Now open Windows Internet Explorer--> Settings--> Select Internet options-->Open Languages as shown below :-

Step 11 :-Now Set the preferences of languages in your browser as shown below:-

Step 12 :-Now Run the application (press F5)-->If your Browser language is French then you will see following output as shown below :- 

Step 13 :- Now Change Internet Explorer Browser language = Urdu --> and Run the application,you will see following output as shown below :-

Step 14 :- Now Change Internet Explorer Browser language = English(us) --> and Run the application,you will see following output as shown below :-

For More...
  1. .NET 1200+ Interview Questions and Answers for jobs seekers
  2. Learn C# Complete concepts with Real life Examples
  3. Learn SQL Complete Concepts With Examples
  4. OOPS concepts in C# with real life examples
  5. Create setup file(.exe) with examples
  6. How to Add .mdf database on asp.net website
  7. Learn complete concepts of Crystal Reports with Examples
Download Whole Attached File
        Download

0 comments:

Post a comment

Powered by Blogger.