Showing posts with label AspNet. Show all posts
Showing posts with label AspNet. Show all posts

Sunday, November 16, 2014

Multilingual Website in Asp.Net

Introduction:-This Article talks about creating Multilingual Website in Asp.net

Step 1:- Create a New ASP.NET Empty Web Application.

Step 2:- Add a new Webform and add below sample code for user interface inside form tag.

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></asp:ToolkitScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
           
        <div>
            <center>
                 <table>
            <tr>
                <td colspan="2">
                    <h2>Multilingual Demo</h2>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="right">
                    <asp:DropDownList ID="ddlLang" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlLang_SelectedIndexChanged">
                        <asp:ListItem Text="English" Value="en-US"></asp:ListItem>
                        <asp:ListItem Text="français" Value="fr-FR"></asp:ListItem>
                        <asp:ListItem Text="español" Value="es-ES"></asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblName" runat="server" Text="Name" meta:resourcekey="lblNameResource1"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtName" runat="server" meta:resourcekey="txtNameResource1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblEmail" runat="server" Text="Email" meta:resourcekey="lblEmailResource1"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtEmail" runat="server" meta:resourcekey="txtEmailResource1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <asp:Label ID="lblPhone" runat="server" Text="Phone" meta:resourcekey="lblPhoneResource1"></asp:Label>
                </td>
                <td>
                    <asp:TextBox ID="txtPhone" runat="server" meta:resourcekey="txtPhoneResource1"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <br />
                </td>
            </tr>
            <tr>
                <td>
                   
                </td>
                <td>
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" />
                    <asp:Button ID="btnReset" runat="server" Text="Reset" />
                </td>
            </tr>
        </table>
            </center>
        </div>

        </ContentTemplate>
    </asp:UpdatePanel>

Step 3:- Now Add ASP.NET folder App_GlobalResources in order to save language resource file (.resx).
Right click  on project name in solution exploreràAddàAdd ASP.NET FolderàApp_GlobalResources














Step 4:- Add Resource file for different language inside App_GlobalResources folder.
Right Click App_GlobalResourcesàAddàNew ItemàResources File (.resx)
Note:-While naming file makes sure you follow below name.












List of different culture specification along with their name is available here

Step 5:- Now change Resource file Build Action to Embedded Resource.
Right Click Resource fileàpropertyàBuild Action=Embedded Resources.
















Step 6:- Write below code in the code-behind file of the created Webform.
Firstly import few required namespaces

using System;
using System.Resources;
using System.Globalization;
using System.Threading;
using System.Reflection;

ResourceManager resourceManager; //use to access cultural specific resources at runtime.
        CultureInfo cultureInfo; //provide information related to specific culture.


        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["Lang"]==null)
            {
                Session["Lang"] = Request.UserLanguages[0];//represent array of client language preferences.
            }
            if(!IsPostBack)
            {
                loadCulture();
            }
        }

        private void loadCulture()
        {
            Thread.CurrentThread.CurrentCulture = new CultureInfo(Session["Lang"].ToString()); //fetch language preference.
            resourceManager = new ResourceManager("MultilingualDemo.App_GlobalResources.Lang", Assembly.GetExecutingAssembly());
            cultureInfo = Thread.CurrentThread.CurrentCulture; //fetch language details.

          
            lblName.Text = resourceManager.GetString("Name", cultureInfo);
            lblEmail.Text = resourceManager.GetString("Email", cultureInfo);
            lblPhone.Text = resourceManager.GetString("Phone", cultureInfo);
            btnSubmit.Text = resourceManager.GetString("Submit", cultureInfo);
            btnReset.Text = resourceManager.GetString("Reset", cultureInfo);
        }

        protected void ddlLang_SelectedIndexChanged(object sender, EventArgs e)
        {
            Session["Lang"] = ddlLang.SelectedValue;
            loadCulture();
        }

Step 7:- Preview of the Work


















Link to Github code

Hope you enjoyed it!!

Wednesday, October 22, 2014

How to Integrate Visual Studio with Github Repository

Note:-  This Article is featured as the article of the day at Asp.Net Community.

Introduction:-This articles describes how to integrate visual studio with github repository and commit your local changes to github repository.

Step 1:-Install ankhsvn from here and integrate with Visual studio as describe in this article.

Step 2:-Install tortoisesvn from here

Step 3:- Create New Repository in Github as shown below




Step 4:- Copy the Subversion Checkout URL of the Repository as shown below:-


Step 5:- Right Click on desktop or wherever you would like to create your project folder and select SVN Checkout.

Step 6:- Paste the copied Checkout url from step4 in the URL of Repository Field and click OK as shown below:-

Step 7:-Now create new Project in Visual Studio and select location of that project as the trunk folder of the previously created checkout directory and also add that project to Subversion and click OK as shown below:-


Step 8:- It will asked you would like to mark Demopurpose.sln as managed by Subversion, say yes.


Step 9:- Now Right Click the Solution and select Commit Solution Changes, in order to commit local changes to Github.


Step 10:- Add any new Item in the application, build the application and then commit it as shown below.




Step 11:- Confirm your local changes to Github by browsing through your Github repository


Hope you enjoyed it!!!