[英]asp.net 4.5 TextBox HTML Encoding
I have an aspx that cotains this code: 我有一个aspx,包含以下代码:
<asp:FormView runat="server"
ID="VeranstaltungDetailForm"
ItemType="Budgetverwaltung.Models.Veranstaltung"
DataKeyNames="VeranstaltungsId"
SelectMethod="GetItem"
InsertMethod="InsertItem"
UpdateMethod="UpdateItem"
OnDataBinding="VeranstaltungDetailForm_DataBinding"
OnDataBound="VeranstaltungDetailForm_DataBound"
OnItemCommand="VeranstaltungDetailForm_ItemCommand">
<ItemTemplate>
<fieldset>
<legend><%#: Item.Bezeichnung %> (<%#: Item.Veranstaltungsnummer %>)</legend>
<table class="content-table">
<tr>
<td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
<td class="light-table"><%#: Item.Beschreibung %></td>
<td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
<td class="light-table"><%# Item.Ort %></td>
</tr>
</table>
</fieldset>
</ItemTemplate>
<InsertItemTemplate>
<fieldset>
<legend>Neue Veranstaltung anlegen</legend>
<table class="content-table">
<tr>
<td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
<td class="light-table"><asp:TextBox runat="server" ID="insert_beschreibung" Text="<%#: BindItem.Beschreibung %>"></asp:TextBox></td>
<td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
<td class="light-table"><asp:TextBox runat="server" ID="insert_ort" Text="<%#: BindItem.Ort %>"></asp:TextBox></td>
</tr>
</table>
</fieldset>
</InsertItemTemplate>
<EditItemTemplate>
<fieldset>
<legend>Veranstaltung bearbeiten "<%#: Item.Bezeichnung %>"</legend>
<dl>
<table class="content-table">
<tr>
<td class="dark-table"><span style="font-weight:bold;">Beschreibung:</span></td>
<td class="light-table"><asp:TextBox runat="server" ID="edit_beschreibung" Text="<%# BindItem.Beschreibung %>"></asp:TextBox></td>
<td class="dark-table"><span style="font-weight:bold;">Ort:</span></td>
<td class="light-table"><asp:TextBox runat="server" ID="edit_ort" Text="<%#: BindItem.Ort %>"></asp:TextBox></td>
</tr>
</table>
</dl>
</fieldset>
</EditItemTemplate>
</asp:FormView>
The data is managed by Entity Framework. 数据由实体框架管理。 In most cases, everything is working fine.
在大多数情况下,一切正常。 But if I enter Umlaute (ÄÖÜ äöü) I run into problems.
但是,如果我进入Umlaute(ÄÖÜäöü),就会遇到问题。 When I enter them and save, everything is fine.
当我输入它们并保存时,一切都很好。 The Data appears correctly in the database.
数据正确显示在数据库中。 When I view the data, eg , everything is fine.
当我查看数据时,例如,一切都很好。 But when I try to edit the data in the data gets html-encoded as ÄÖÜ and I can't save it again.
但是,当我尝试编辑数据时,数据中的数据被html编码为ÄÖÜ,而我无法再次保存。 I'm no expert at asp.net so I'm at a loss right now.
我不是asp.net的专家,所以现在很茫然。 Where is my mistake?
我的错误在哪里? Thanks for your help.
谢谢你的帮助。
尝试看一下: 字符串编码-德语变音符号
Without knowing your configuration I would assume that your content, when loaded from the server, is probably character set UTF-8
, which causes non-UTF-8 characters like 'Ü' to be HTML-encoded. 在不知道您的配置的情况下,我会假设您的内容从服务器加载时可能是字符集
UTF-8
,这会导致非UTF-8字符(如Ü)被HTML编码。 Thus your textbox is displaying the HTML-encoded characters instead of the original UTF-16
characters - but when rendered in your normal ItemTemplate the browser respects the encoding and this appears perfectly fine. 因此,您的文本框显示的是HTML编码的字符,而不是原始的
UTF-16
字符-但是当在常规ItemTemplate中呈现时,浏览器会遵循编码方式,这看起来非常好。
You could try to force UTF-16 encoding on all responses using this approach in your web.config which should ensure that your umlaut characters never get encoded in a response: 您可以尝试在web.config中使用此方法在所有响应上强制采用UTF-16编码,这应确保您的变音符永远不会在响应中编码:
<configuration>
<system.web>
<globalization requestEncoding="utf-16" responseEncoding="utf-16" />
</system.web>
</configuration>
YMMV. YMMV。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.