This is a migrated thread and some comments may be shown as answers.

[Solved] Title encoding

6 Answers 113 Views
Window
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jacques
Top achievements
Rank 1
Jacques asked on 04 Oct 2011, 03:57 PM

How can Window title be set to accept utf-8 encoding?

The following show how Telerik Window is used. The action 'Edit' in controller 'Adresse' renders a partial view of an address.
After loading, the character 'à' is not redered properly in the Window's title bar.

@(Html.Telerik().Window()
    .Name("Window")
    .Title("Adresse à modifier")
    .Buttons(b => b.Maximize().Close())
    .Visible(false)
    .Modal(true)
    .Width(500)
    .Height(310)
)
 
 
@(Html.Telerik().Grid(Model)
    .Name("Grid")
    //.ToolBar(commands => commands.Insert())
    .ToolBar(commands => commands.Template(
        @<text>
            <input type='button' value='Ajouter un contenu' onclick="insertRecord()" />
        </text>
    ))
....//removed for brievety
        columns.Template(
            @<text>
                <input type="button" value="Editer" onclick="updateRecord('@item.ID')" />
                <input type="button" value="Enlever" onclick="deleteRecord('@item.ID')" />
            </text>
        ).Width(150);
    })
....//removed for brievety
)
<script type="text/javascript">
    function insertRecord() {
        var url = '@Url.Action("Edit", "Adresse")';
        $.post(url, {}, function (data) {
            var window = $('#Window').data('tWindow');
            window.title("Nouvelle adresse");
            window.open();
            window.content(data);
        });
    }
    function updateRecord(id) {
        var url = '@Url.Action("Edit", "Adresse")';
        $.post(url, {}, function (data) {
            var window = $('#Window').data('tWindow');
            window.title("Adresse à modifier");
            window.open();
            window.content(data);
        });
    }


I have tried the following without any success. Can you help resolve this issue?
Thanks

function updateRecord(id) {
    var url = '@Url.Action("Edit", "Adresse")';
    $.ajax({
        type: 'POST',
        url: url,
        data: { id: id },
        success: function (data) {
            var window = $('#Window').data('tWindow');
            window.title("Adresse à modifier");
            window.content(data);
            window.open();
        },
        scriptCharset: "utf-8",
        contentType: "text/html; charset=utf-8"
    });
}

6 Answers, 1 is accepted

Sort by
0
Adam
Top achievements
Rank 1
answered on 10 Feb 2012, 09:09 PM
Hoping this can be resolved without a hack soon

In the window title I get "Iniciar sesi&#243;n" instead of "Iniciar sesión"

Can be resolved with a hack:

@Html.Telerik().Window().Name("WindowName").Title(Html.Raw(Resources.LabelLogin).ToHtmlString())


or in javascript:

var window = $("#WindowName").data("tWindow");
window.title('@Html.Raw(Resources.LabelLogin)');
0
Alex Gyoshev
Telerik team
answered on 15 Feb 2012, 05:01 PM
The window title should accept the strings, if the page itself is utf-8 encoded. In particular, the window in the online demos can accept the utf-8 strings if you set them through the javascript console. Using ToHtmlString encodes the characters as entities, therefore the hack works. Can you please verify that the pages are utf-8 encoded?

All the best,
Alex Gyoshev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Adam
Top achievements
Rank 1
answered on 15 Feb 2012, 06:04 PM
Thanks for the response Alex,

My layout page defines utf-8 encoding:

<head>
    <meta charset="utf-8" />
    ...
</head>

The view with the telerik window is a partial view, rendered in the layout page using @Html.Action(), but I don't think that should make a difference. Below is the window defined in my partial view. I actually discovered that I didn't need to do the ToHtmlString() call; it was the window content partial view causing the problem.

Html.Telerik().Window()
                .Name("AuthenticationWindow")
                .Modal(true)
                .Title(Resources.LabelLogin)
                .LoadContentFrom("LoginForm", "Authentication")
                .Render();

So far everything works. My window content is another partial view. In that partial view I have a $(document).ready() handler which sets the window title for whichever form gets loaded into the window content:

$(document).ready(function () {
        var window = $("#AuthenticationWindow").data("tWindow");
        if (window != null) {
            window.title('@Resources.LabelLogin');
        }
}

This is where the problem occurs. If I comment out the javascript line to change the title it is fine (or if I wrap it in Html.Raw()). However, I replace the window content later on with different forms, so I need to change the window title in javascript. Somehow, the window content isn't utf-8 encoded or I am doing something wrong I guess.
0
Alex Gyoshev
Telerik team
answered on 16 Feb 2012, 12:55 PM
Hello Adam,

Please ensure that your page is served (and saved) with the proper encoding. You can inspect that in the network tab of the chrome developer tools or the net tab in firebug. Refer to the attached project for a demo that shows that the window itself does not encode the content.

Kind regards,
Alex Gyoshev
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
0
Adam
Top achievements
Rank 1
answered on 01 Mar 2012, 10:03 PM
Excuse the late reply,

I did verify in the browser that the request has UTF-8 encoding so I am not sure what would be causing the issue.
0
Dimo
Telerik team
answered on 02 Mar 2012, 10:50 AM
Hi Adam,

Did you try the attached sample application, which shows how UTF-8 characters work in the Window title? If you have troubles with it, then the problem must be in the browser settings or wrong encoding headers sent by the web server.

Kind regards,
Dimo
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now.
Tags
Window
Asked by
Jacques
Top achievements
Rank 1
Answers by
Adam
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Dimo
Telerik team
Share this question
or