ASP.NET 4.0 DropDownList在文本中带有单引号 [英] ASP.NET 4.0 DropDownList with single quotes in text

查看:75
本文介绍了ASP.NET 4.0 DropDownList在文本中带有单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个asp:DropDownList,我们在服务器端填充

We have a asp:DropDownList that we populate server side with

ddlBranch.Items.Add(new ListItem("TEST","This is a's test"));

当它在.NET 3.5下编译并运行时,我们会看到文本这是一个测试"

When this is compiled and run under .NET 3.5 we see the text "This is a's test"

但是,当它在.NET 4.0中编译并运行时,我们会看到文本这是'的测试"

However when this is compiled and run under .NET 4.0 we see the text "This is a's test"

我们已将以下内容添加到我们的web.config中,并且没有更改.

We have added the following to our web.config and there was no change.

<pages controlRenderingCompatibilityVersion="3.5" />

目前我们已经退回到.NET 3.5,但是我们想知道是否有解决此问题的方法,或者这是一个已知的渲染问题,还是设计使然.

For the time being we have dropped back to .NET 3.5 however we would like to know if there is a way to work around this or if this is a known rendering issue or is by design.

TIA

AJ

推荐答案

大家好
感谢您的答复,他们使我更深入地研究了代码,以寻找某个地方的编码.原来那是一个:

Hi All
Thanks for the responses and they led me to look deeper into the code looking for an Encode somewhere. It turns out there that was a:

Server.HtmlEncode(input)

在基类中的所有控件上执行

.

being performed on all controls in a base page class.

现在我认为确实有问题,这实际上是我的RTFM案例

Now what I thought was a problem really turns out to be a case of RTFM on my part

来自 http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
HtmlEncode和UrlEncode现在可以对单引号进行编码

From http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes
HtmlEncode and UrlEncode Now Encode Single Quotation Marks

在ASP.NET 4中,HttpUtility和> HttpServerUtility类的HtmlEncode和UrlEncode方法已更新为对单引号字符>(')进行编码,如下所示:

In ASP.NET 4, the HtmlEncode and UrlEncode methods of the HttpUtility and >HttpServerUtility classes have been updated to encode the single quotation mark character >(') as follows:

HtmlEncode方法将单引号的实例编码为'. UrlEncode方法将单引号的实例编码为%27.

The HtmlEncode method encodes instances of the single quotation mark as ' . The UrlEncode method encodes instances of the single quotation mark as %27.

因此,当我使用.NET3.5时,HtmlEncode会忽略我的单引号('),但是当切换到.NET 4.0时,HtmlEncode不会忽略它.

So when I was using .NET3.5 my single quote ( ' ) was being ignored by the HtmlEncode but when switching to .NET 4.0 it was not being ignored by HtmlEncode.

再次感谢人们对这个问题的所有回答和贡献.

Thanks again for all the responses and work that people put in to this question.

致谢

AJ

这篇关于ASP.NET 4.0 DropDownList在文本中带有单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆