Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UpdatePanel seems to re-encode characters in the page title?

I have pages with special characters in the title for proper typography, for example it says Exchange ‘07 Groups" with a proper apostrophe, not a single quote. The HTML entity for the apostrophe is ‘

So, I've found that if I set the page title from VB, the title displays just fine, but as soon as an update panel updates that HTML entity gets re-encoded and displays incorrectly as "Exchange ‘07 Groups"

So here's my code where I simply set the page title, then an update panel, and a button to update it...

<script runat="server">
    Protected Sub Page_Load(...) Handles Me.Load
       Page.Title = "Exchange &#8216;07 Groups"
    End Sub

    Protected Sub uxLnkDoClick(ByVal sender As Object, ByVal e As System.EventArgs)
        uxLitLoaded.Text = "Loaded!"
    End Sub
</script>

<!DOCTYPE html>
<html>
<head runat="server"></head>
<body>
<form id="form1" runat="server">
    <asp:ScriptManager runat="server"></asp:ScriptManager>    
    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:LinkButton runat="server" ID="uxLnkDo" OnClick="uxLnkDoClick" Text="Do Something" />
            <asp:Literal runat="server" ID="uxLitLoaded" />
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="uxLnkDo" />
        </Triggers>
    </asp:UpdatePanel>
</form>
</body>
</html>

What can be done about this?

like image 252
FiniteLooper Avatar asked Sep 08 '10 18:09

FiniteLooper


2 Answers

In your code to set the page title, wrap the text in Server.HtmlDecode:

Page.Title = Server.HtmlDecode("Exchange &#8216;07 Groups")
like image 55
adrianstovall Avatar answered Nov 11 '22 07:11

adrianstovall


I had the same situation with the SM (service mark, as opposed to TM for trademark) which we did setting the page title with Page.Title = "My Company &#8480"; . It reencoded it upon postback.

What we did is in the page head we statically added it < title >My Company &#8480;< /title >

Worked like a charm.

like image 32
xmorera Avatar answered Nov 11 '22 09:11

xmorera