在输出到html之前如何停止asp.net编码字符? [英] How to stop asp.net encoding characters before outputing to html?
本文介绍了在输出到html之前如何停止asp.net编码字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个为我生成JavaScript代码的函数。
I have a function that generates a javascript code for me.
<img src="abc.png" alt="hello" onclick="<%: getOnCilckJS(arg) %>" />
c#代码
protected String getOnCilckJS(int arg)
{
if (arg==1)
{
return "alert('hello world');";
}
else
{ return "alert('hello universe');";
}
}
除了在页面加载asp之外,其他所有方法都可以正常工作.net将单引号'
转换为编码的html字符串(&#39;
)
all works fine apart from when the page is loaded asp.net converts single quotations '
to the encoded html string ('
)
如何避免这种情况并使'
出现在html中?
How can I avoid this and make '
appear in the html?
推荐答案
您的代码对我有用:
但只需将<%:更改为<%= (并且我自己发送参数)
But just change <%: to <%= ( and I send the parameter myself)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="xxxx.aspx.cs" Inherits="SampleAngularApp.xxxx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
**<img src="abc.png" alt="hello" onclick="<%= getOnCilckJS(11) %>" />**
</div>
</form>
</body>
</html>
服务器端
**protected string getOnCilckJS(int arg)**
{
if (arg == 1)
{
return "alert('hello world');";
}
else
{
return "alert('hello universe');";
}
}
我收到的警报消息没有任何单引号
I got the alert message without any single quote
这篇关于在输出到html之前如何停止asp.net编码字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文