C#attributecollection.add撇号

C#attributecollection.add撇号,c#,c#-4.0,attributes,html-table,C#,C# 4.0,Attributes,Html Table,我有个问题 以下是我的代码行: HtmlTableRow row = new HtmlTableRow(); row.Attributes.Add("style", "cursor: pointer;"); row.Attributes.Add("onClick", string.Format("toggle('{0}');", AttributeName)); 我在.NET2.0中使用了它,效果很好。但现在我正在使用.NET4.0和撇号 转换为'在我的网页,它不再工作 我怎样才能得到撇

我有个问题

以下是我的代码行:

HtmlTableRow row = new HtmlTableRow();
row.Attributes.Add("style", "cursor: pointer;");
row.Attributes.Add("onClick", string.Format("toggle('{0}');", AttributeName));
我在.NET2.0中使用了它,效果很好。但现在我正在使用.NET4.0和撇号 转换为
'在我的网页,它不再工作

我怎样才能得到撇号本身或绕过这个问题


注意,这似乎是一个

编码为
'
完全有效,因此这不是您的实际问题。使用
onclick=“toggle('asdf')”
onclick=“toggle(';asdf';)”
是等效的

演示:


您必须寻找代码不工作的其他原因。

好的。。。还没有回答。。。这就是我的工作

HtmlGenericControl dynDiv = new HtmlGenericControl("div");

dynDiv = Replace(dynDiv, "'", "'");

public HtmlGenericControl Replace(HtmlGenericControl htmlGenericControl, string    
source, string target)
{
     StringWriter sw = new StringWriter();
     HtmlTextWriter htmlTextWriter = new HtmlTextWriter(sw);
     htmlGenericControl.RenderControl(htmlTextWriter);
     string str = sw.GetStringBuilder().ToString();

     str = str.Replace(source, target);
     htmlGenericControl.InnerHtml = str;

     return htmlGenericControl;
}
小错误-出于某种原因,它复制了ResultPage.aspx中的“div”标记,但它不会干扰代码,所以我不在乎

但是-当我尝试将其用于
HtmlGenericControl script=newhtmlgenericcontrol(“script”)它会破坏代码。因此,在本文中,解决方法是将实际的java脚本代码直接植入ResultPage.aspx-->view Designer-->源代码中

<script type="text/javascript">
    My Script (with the apostrophe...)
</script>

我的脚本(带撇号…)

享受!:)

嗨,当我在源代码中进行查找/替换时,一切又恢复正常了。。。这就是为什么我仍然认为这就是问题所在。。。