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 ‘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?
In your code to set the page title, wrap the text in Server.HtmlDecode:
Page.Title = Server.HtmlDecode("Exchange ‘07 Groups")
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 ℠";
. It reencoded it upon postback.
What we did is in the page head we statically added it
< title >My Company ℠< /title >
Worked like a charm.
The reason it displays it incorrectly is because .Net is attempting to be safe and HTML encode the title (for prevention of the multiple types of attacks that are possible).
In ASP.Net MVC, you can now use the Html.Raw() method. As far as straight ASP.net, I don't know what the method would be.
add this check
if(!Page.IsPostBack)
{
Page.Title = "Exchange ‘07 Groups"
}
or you can simply set the title property in html if its not dynamic!
精彩评论