从 C# 代码隐藏中停止编码 HTML 中的字符
Stop Characters from Encoding in HTML from C# Code Behind
您好,提前谢谢您。我正在从后面的 C# 代码生成控件,并希望应用一个 onclick 属性,该属性将发送模态以阻止显示。当代码执行时,onclick 函数字符串中的撇号被编码为 '
,我想阻止这种情况发生并传递原始文本。
我已经尝试了以下方法来解决没有解决的问题:
\'
''
<%= myString %>
HtmlString(myString).ToHtmlString();
可能还有其他我尝试过的迭代,但我都忘记了它们。
这是创建控件的代码部分:
HtmlGenericControl viewMoreInfo = new HtmlGenericControl("span");
//HtmlString onclick1 = new HtmlString($"document.getElementById('{i.il_itemcode}Modal').style.display = 'block'");
string onclick1 = $"document.getElementById('{i.il_itemcode}Modal').style.display = 'block'";
viewMoreInfo.Attributes["onclick"] = onclick1;
viewMoreInfo.Attributes["class"] = "w3-bar-item w3-button w3-white w3-xlarge w3-right";
viewMoreInfo.InnerText = "+";
这是它呈现的示例:
<span onclick="document.getElementById('TEST1Modal').style.display = 'block'" class="w3-bar-item w3-button w3-white w3-xlarge w3-right">+</span>
我需要正确呈现撇号才能使函数正常工作。
任何帮助将不胜感激。
您的问题具有误导性,因为 "I need the apostrophe to render correctly for the function to work." 不正确。请注意以下内容,它是您的示例的精确副本,点击事件在当前呈现时工作正常。
<p id="TEST1Modal" style="display:none">This is hidden until clicked</p>
<span onclick="document.getElementById('TEST1Modal').style.display = 'block'" class="w3-bar-item w3-button w3-white w3-xlarge w3-right">+</span>
您好,提前谢谢您。我正在从后面的 C# 代码生成控件,并希望应用一个 onclick 属性,该属性将发送模态以阻止显示。当代码执行时,onclick 函数字符串中的撇号被编码为 '
,我想阻止这种情况发生并传递原始文本。
我已经尝试了以下方法来解决没有解决的问题:
\'
''
<%= myString %>
HtmlString(myString).ToHtmlString();
可能还有其他我尝试过的迭代,但我都忘记了它们。
这是创建控件的代码部分:
HtmlGenericControl viewMoreInfo = new HtmlGenericControl("span");
//HtmlString onclick1 = new HtmlString($"document.getElementById('{i.il_itemcode}Modal').style.display = 'block'");
string onclick1 = $"document.getElementById('{i.il_itemcode}Modal').style.display = 'block'";
viewMoreInfo.Attributes["onclick"] = onclick1;
viewMoreInfo.Attributes["class"] = "w3-bar-item w3-button w3-white w3-xlarge w3-right";
viewMoreInfo.InnerText = "+";
这是它呈现的示例:
<span onclick="document.getElementById('TEST1Modal').style.display = 'block'" class="w3-bar-item w3-button w3-white w3-xlarge w3-right">+</span>
我需要正确呈现撇号才能使函数正常工作。
任何帮助将不胜感激。
您的问题具有误导性,因为 "I need the apostrophe to render correctly for the function to work." 不正确。请注意以下内容,它是您的示例的精确副本,点击事件在当前呈现时工作正常。
<p id="TEST1Modal" style="display:none">This is hidden until clicked</p>
<span onclick="document.getElementById('TEST1Modal').style.display = 'block'" class="w3-bar-item w3-button w3-white w3-xlarge w3-right">+</span>