Category Archives: Localize

[RESOLVED] SiteMapNode and ExplicitResourceKeys

has anyone ever use the SiteMap node constructor that takes ExplicitResourceKeys parameter?

I dont find any detail documentation by microsoft on localizing sitemap. I know how to localize XmlSiteMapProvider. But im using SqlSiteMapProvider and i want to localize it. One of the parameter of SiteMapNode takes ExplicitResourceKeys. But i dont know what to pass there. Its a namevalue collection type

Anyone knows? my resources are also stored in SQL and i have custom SQLResourceProvider which is working  fine with it.

never mind i solved it

Can you tell us how did you to solve this problem?

I’m using SQL site map provider from http://msdn.microsoft.com/en-us/magazine/cc163657.aspx  I have added one more column in [SiteMap] table to store resource key for the Title. If you want to localize description also then you have to add one more column for description resource key. Then i changed CreateSiteMapNodeFromDataReader() method to build explicitResourceKey collection. I’m also using SQL Resource provider from http://msdn.microsoft.com/en-us/library/aa905797.aspx 

IMPORTANT: I’m using SiteMap provider for Menu control which will be on masterpage.So all my SiteMap resources are storeded in SQL database as Global resources. [StringResources] table has column called “ResourceType”. This column’s value will be common to all SiteMap related resources. This is the class name that we have use to while building explicitResourceKey collection. I used some constant value. Eg “SqlSiteMapProvider“

 

private const string ClassName = "SqlSiteMapProvider";

private SiteMapNode CreateSiteMapNodeFromDataReader(DbDataReader reader)
{

            // Make sure the node ID is present

            if (reader.IsDBNull(_indexID))

                throw new ProviderException(_errmsg1);

            // Get the node ID from the DataReader

            int id = reader.GetInt32(_indexID);

            // Make sure the node ID is unique

            if (_nodes.ContainsKey(id))

                throw new ProviderException(_errmsg2);


            // Get title, URL, description, and roles from the DataReader

            string title = reader.IsDBNull(_indexTitle) ?
                null : reader.GetString(_indexTitle).Trim();
            string url = reader.IsDBNull(_indexUrl) ?
                null : reader.GetString(_indexUrl).Trim();
            string description = reader.IsDBNull(_indexDesc) ?
                null : reader.GetString(_indexDesc).Trim();
            string roles = reader.IsDBNull(_indexRoles) ?
                null : reader.GetString(_indexRoles).Trim();
            string resourcekey = reader.IsDBNull(_indexResourceKey) ?
                null : reader.GetString(_indexResourceKey).Trim();


            // If roles were specified, turn the list into a string array

            string[] rolelist = null;
            if (!String.IsNullOrEmpty(roles))
                rolelist = roles.Split(new char[] { ',', ';' }, 512);
            SiteMapNode node = null;
            //if node has localize value in database then get that
            //else use the defualt one

            if (EnableLocalization && !string.IsNullOrEmpty(resourcekey))
            {
                NameValueCollection keyCollection = new NameValueCollection();
                keyCollection.Add("Title", ClassName);
                keyCollection.Add("Title", resourcekey);
                node = new SiteMapNode(this, id.ToString(), url,
                    title, description, rolelist, null, keyCollection, null);

                //TO DO: we can also localize description property
                //keyCollection.Add("Description", ClassName);
                //keyCollection.Add("Description", descriptionresourcekey);

            }
            else
            {
                node = new SiteMapNode(this, id.ToString(), url,
                            title, description, rolelist, null, null, null);
            }          

            // Record the node in the _nodes dictionary
            _nodes.Add(id, node);

            // Return the node
            return node;
        }



 

Thanks for sharing!

I think many others will benefit from it.

lax4u

IMPORTANT: I’m using SiteMap provider for Menu control which will be on masterpage.So all my SiteMap resources are storeded in SQL database as Global resources. [StringResources] table has column called “ResourceType”. This column’s value will be common to all SiteMap related resources. This is the class name that we have use to while building explicitResourceKey collection. I used some constant value. Eg “SqlSiteMapProvider“ 

I have get the SQL Site map work alone, the Resource Provider alone, but combined i can't get it working. it doesn't get localized. Debugging in your added code shows that it actually adds the keyColelction, so I guess it has to do with my items in the database.

If in the Sitemap table my item have the value of the column "resourcekey" to "Sitemap_Home" and I haven't changed the "Title" in your code.
Should it be my classname, like your "SqlSiteMapProvider" or anything else as ResourceType?
Should it be "Sitemap_Home" or "Sitemap_Home.Title" in the resourcekey in StingResourcetable? 

 

Greateful for help.

Regards Pelle

@lax4u

Would you mind posting your complete solution (generic-ized of course) for the benefit of those who are... eh hem... less savvy.  You're doing exactly what I'm hoping to accomplish.

Thanks!

thanks for your sharring i try also create static site map driving from database and also i need for menu items localization i created a resource file for resources to get the data from there and also created some nameValueCollection for createNode() method but it doesn't work all i see is the titel value if you can please let me know how you change the enabel localization value to true and if you can please give us more information thanks

[RESOLVED] 2 questions regarding resource pages

Hi - I;ve not user resource pages in .net before but have been tasked with converting an existing app to make it multilingual. I have two specific questions about getting it working how I want.

1. Explicitly setting the culture: I don't want to rely on the browser to set the culture for my users I want to do it via code. I've tried to do this within the Page_Load method and have tried a couple of different ways, none of which seemed to have worked:

System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("fr-FR");

Page.Culture = "fr-FR";

The page is still displaying data from the en-GB file I have (which is what my browser is set to).

2: I have some static text in my HTML that I would like to make multi-lingual. I have tried using the following server side control to achieve this but it always displays what is in the "Text" attribute rather than looking up the value "LiteralResource1" from the page's resource file

        <asp:Localize runat="server"
            ID="WelcomeMessage"
            Text="Welcome!" meta:resourcekey="LiteralResource1" />
I have gone through a few of Microsoft's help pages and examples for this but just can't seem to get it to work so any help would be greatly appreciated.

Thanks,

 Brian

 

 

Aspx Code: 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ResourceExample.aspx.cs"
    Inherits="SampleWeb.ResourceExample" %>

<!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>Multi langauge example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table border="1px">
            <tr>
                <td style="width: 120px" align="right">
                    Change langauge :</td>
                <td>
                    <asp:DropDownList ID="ddlLanguage" runat="server" AutoPostBack="True">
                        <asp:ListItem Value="Auto">Auto</asp:ListItem>
                        <asp:ListItem Value="ar-EG">Arabic</asp:ListItem>
                        <asp:ListItem Value="de-DE">German</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td align="right">
                    Back :
                </td>
                <td>
                    <asp:Button ID="btnBack" runat="server" Text="<%$ Resources:MyResource, ButtonBack %>" />
                </td>
            </tr>
            <tr>
                <td align="right">
                    Delete :
                </td>
                <td>
                    <asp:Button ID="btnDelete" runat="server" Text="<%$ Resources:MyResource, ButtonDelete %>" />
                </td>
            </tr>
            <tr>
                <td align="right">
                    Ok :
                </td>
                <td>
                    <asp:Button ID="btnOk" runat="server" Text="<%$ Resources:MyResource, ButtonOk %>" />
                </td>
            </tr>
            <tr>
                <td align="right">
                    Cancel :
                </td>
                <td>
                    <asp:Button ID="btnCancel" runat="server" Text="<%$ Resources:MyResource, ButtonCancel %> " />
                </td>
            </tr>
        </table>
    </div>
    </form>
</body>
</html>

 Code Behind:

using System.Threading;
using System.Globalization;

namespace SampleWeb
{
    public partial class ResourceExample : System.Web.UI.Page
    {
        protected override void InitializeCulture()
        {
            string strlang = Request["ddlLanguage"];

            if (!string.IsNullOrEmpty(strlang))
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(strlang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(strlang);
            }
        }
    }
}


Apart from the above files, I have added resource files for each langauges with Name and value.

Hope the above code will solves your first problem.

Thanks for your reply - I actually found a way of getting it to work without including C# code in the page itself.

What I was doing wrong is you need to override the InitializeCulture method and change the culture there rather than in Page_Load.

Also I wasn't including the .text in my keynames in the resource file which is why asp:Localize wasn't working :)

[RESOLVED] Panel cannot display inline

my application let user to input time-off by exact time or am/pm.

as to hide/show the timeselector and am/pm radio button, i had use two separate panel.

but there is a problem of timeselector that cannot display inline. (when chose Exact time, the timeselector will display in other line).

 

 

<asp:Panel ID="panel_from_date" runat="server"  style="display:inline;">
<cc1:datetextbox id="tb_from_date" runat="server" borderstyle="Solid" width="75px" CausesValidation="True"></cc1:datetextbox>
&nbsp;
<cc1:datepicker id="DatePicker1" runat="server" controltopick="ctl00$CPH1$tb_from_date" meta:resourcekey="DatePickerResource"></cc1:datepicker>
</asp:Panel>

<asp:Panel ID="panel_from_hr" runat="server"  style="display:inline;">
<MKB:TimeSelector ID="TimeSelector_from_time" runat="server" DisplaySeconds="False" MinuteIncrement="1" AmPm="PM" BorderColor="Silver" Date="" Hour="0" Minute="0" Second="0" SelectedTimeFormat="Twelve"></MKB:TimeSelector>
</asp:Panel>
            
<asp:Panel ID="panel_from_am_pm" runat="server" Visible="False" style="display:inline;">
<asp:RadioButton ID="rb_from_am" runat="server" Checked="True" GroupName="from_am_pm" />
<asp:Localize runat="server" ID="text_from_am" Text="am" meta:resourcekey="text_am" />
<asp:RadioButton ID="rb_from_pm" runat="server" GroupName="from_am_pm" />
<asp:Localize runat="server" ID="text_from_pm" Text="pm" meta:resourcekey="text_pm" />
</asp:Panel>

 

How can i solve this problem ? thanks

Joe

All you have to do is place your controls into Tables. or use css. But generally CSS is used in defining page templates. So You can prefer using Table for your controls inside the page.

Please use appropriate widths or use css in below sample.

also please refer W3Schools - HTML Tables

<asp:Table runat="server" ID="TableControls">
    <asp:TableRow>
        <asp:TableCell>
            <asp:Label runat="server" id="Label1" Text="Time-off Format" />
        </asp:TableCell>
        <asp:TableCell>
            Radio Button for Exact Time.
        </asp:TableCell>
        <asp:TableCell>
            Radio Button for AMPM
        </asp:TableCell>
    </asp:TableRow>


    <asp:TableRow>
        <asp:TableCell Width="">
            From date & Time label
        </asp:TableCell>
        <asp:TableCell Width="">
            TextBox
        </asp:TableCell>
        <asp:TableCell Width="">
            Radio Button for AM
            Radio Button for PM
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell Width="">
            To date & Time label
        </asp:TableCell>
        <asp:TableCell Width="">
            TextBox
        </asp:TableCell>
        <asp:TableCell Width="">
            Radio Button for AM
            Radio Button for PM
        </asp:TableCell>
    </asp:TableRow>

    <asp:TableRow>
        <asp:TableCell Width="">
                    
        </asp:TableCell>
        <asp:TableCell Width="">
            Calclate button
        </asp:TableCell Width="">
        <asp:TableCell Width="">
        </asp:TableCell>
    </asp:TableRow>

    Other Rows comes here.
    Other Rows comes here.
    Other Rows comes here.

</asp:Table>

<asp:Table runat="server" ID="TableFooterSaveClearSubmit">
    <asp:TableRow>
        <asp:TableCell>
            save button
        </asp:TableCell>
        <asp:TableCell>
            clear button
        </asp:TableCell>
        <asp:TableCell>
            submit button
        </asp:TableCell>
    </asp:TableRow>
</asp:Table>

 

You can't use "style=" in a <ASP:Panel>.  You could try using a CssClass, but I don't know if that would work.

You could put your panels inside table cells, if you are willing to go the table layout route.

Given how few controls you're putting inside your panels, I think I might just skip the panels and hide the individual controls.

Try changing the Layout property of RadioButtonList from Table to Flow.

fyi, actually style property works for asp:Panel.

shahed.kazi

fyi, actually style property works for asp:Panel.

If you say so, but it isn't listed here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel_members(v=VS.90).aspx

WombatEd

You can't use "style=" in a <ASP:Panel>

style property works for asp:panel. I've just tested.

<asp:Panel ID="Panel1" style="background-color:Gray;color:White" runat="server">
                SomeText inside Panel
            </asp:Panel>

Style Property is listed in http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.panel_members%28v=VS.90%29.aspx

Style Property is defined in WebControl class, so It must be there in every asp web control.

    public class WebControl : Control, IAttributeAccessor
    {
        .............
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        [WebSysDescription("WebControl_Style")]
        public CssStyleCollection Style { get; }
        .............
     }

 

thank you all.

i used table cell which solved my problem.

 

Joe

[RESOLVED] can I localize the browse text in a fileupload control

Hi all,

Can I localize the browse text in a fileupload control? (flip it between English and French)

Any ideas?

Thanks

Gord

Hi,

as far as i know you can't do that. This is set on browser level if i recall corectly and depends on clients "windows" (os) language.

There are workarrounds available on web ;)

Not directly, no. The file upload is probably the worst HTML element, allowing very little in the way of design and styling. Personally, I always use a third party component, so I get styling as well as async and progress.

You can have a button with text you want to have. Set the css style to overlap the fileupload control..

Thanks all

Tamilmani Kpr

You can have a button with text you want to have. Set the css style to overlap the fileupload control..

Hi Tamilmani Kpr

how would I hook the button control to the fileupload, so as to fire the fileupload control when the css styled button is clicked?

 

thanks

Gord

Hi GordMacDonald,

                  Try this...

<style type="text/css">

.fileUpload
{
    width:84px;
    filter:alpha(opacity=0);
    -moz-opacity:0;
    opacity:0;
    elevation:below;
    position:relative;
    left:-90px;
    top:-3px;
    vertical-align:middle;
    height:26px;
}

</style>

 <input id="Button1" type="button" style="left: 0px; position: relative; top: 1px;
                                width: 73px; font-family: Palatino Linotype" value="Import..."  />
                            <asp:FileUpload runat="server" ID="fileUpload" CssClass="fileUpload" size="1"  />

Tamilmani Kpr

Hi GordMacDonald,

                  Try this...

<style type="text/css">

.fileUpload
{
    width:84px;
    filter:alpha(opacity=0);
    -moz-opacity:0;
    opacity:0;
    elevation:below;
    position:relative;
    left:-90px;
    top:-3px;
    vertical-align:middle;
    height:26px;
}

</style>

 <input id="Button1" type="button" style="left: 0px; position: relative; top: 1px;
                                width: 73px; font-family: Palatino Linotype" value="Import..."  />
                            <asp:FileUpload runat="server" ID="fileUpload" CssClass="fileUpload" size="1"  />

 

Thanks - I will check this out!

You cant do it. Better to use Custom control or Ready to use control for these type of functionality.

its not possible but workaroung is that use a textbox and button and use fileupload control but keep it hidden on button click fire click event of file upload from javascript and on select set file text in textbox.

Firing the fileupload click event on a button click will not work in firefox browser....