停止Attributes.Add将我的JavaScript事件代码转换为HTML [英] Stopping Attributes.Add from converting my JavaScript event code to HTML

查看:74
本文介绍了停止Attributes.Add将我的JavaScript事件代码转换为HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Attributes集合的Add方法向Controls

添加了几个JavaScript事件(onchange,onkeypress等)。但是,如果

JavaScript代码包含某些字符,例如&或者<或几个其他人,它将它们转换成html,例如& amp; amp; amp; amp; amp; amp;或& lt;有时可能会导致我的脚本不起作用。如何阻止ASP.NET执行此操作?

谢谢。

-

Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/

I add several JavaScript events (onchange, onkeypress, etc.) to Controls
using the Add method of the Attributes collection. However, if the
JavaScript code contains certain characters, such as & or < or several
others, it converts them to html, such as &amp; or &lt; which can sometimes
cause my scripts not to work. How can I prevent ASP.NET from doing this?
Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

推荐答案

嗨Nathan,


那是HTML en / decode类。

http://msdn.microsoft.com/library/de...codeTopic1。 asp


我希望这会有所帮助,


Cor


" Nathan索卡尔斯基" < nj ******** @ hotmail.comschreef在bericht

新闻:OW ************* @ TK2MSFTNGP03.phx.gbl ...
Hi Nathan,

For that is the HTML en/decode classes.

http://msdn.microsoft.com/library/de...codeTopic1.asp

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:OW*************@TK2MSFTNGP03.phx.gbl...

>我使用Attributes集合的Add方法向控件添加了几个JavaScript事件(onchange,onkeypress等)。但是,如果
JavaScript代码包含某些字符,例如&或者<或者其他几个,它将它们转换为html,例如& amp;或& lt;有时可能会导致我的脚本无法正常工作。我怎样才能阻止ASP.NET这样做?
谢谢。

-

Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/



那会如果我使用类似

System.Web.UI.HtmlTextWriter的东西,那就太棒了,但我只是在我的* .aspx文件中添加属性对象

声明性地创建。例如,我有以下

作为我的* .aspx文件的一部分:

< asp:TextBox ID =" txtRed" RUNAT = QUOT;服务器" MaxLength =" 3"

Width =" 35px"> 0< / asp:TextBox>

我的* .aspx.vb文件中包含以下内容:

txtRed.Attributes.Add(" onchange"," if(this.value> = 0&& this.value< = 255){"&

redslider.ClientSetFunctionName&"(this.value);} else {this.value ="&

redslider.ClientGetFunctionName&"();}")

当我的页面呈现时,如下所示(注意

&'和<用HTML表示替换):

onchange =" if(this.value> = 0& amp;& amp; this.value& lt; = 255){sliderRed_setvalue(this.value);} else {this.va lue = sliderRed_getvalue ();}"

Server.HtmlDecode()方法对我没有帮助,因为

Attributes.Add()方法接受一个字符串就像它的'第二个参数,和
Server.HtmlDecode()在我的情况下对它没有任何影响,所以我会

实际上是传递相同的字符串。还有其他想法吗?谢谢。

-

Nathan Sokalski
nj * *******@hotmail.com
http:// www.nathansokalski.com/

" Cor Ligthert [MVP]" < no ************ @ planet.nlwrote in message

news:OG ************** @ TK2MSFTNGP04.phx .gbl ...
That would be great if I were using something like the
System.Web.UI.HtmlTextWriter, but I am simply adding attributes objects
created declaratively in my *.aspx file. For example, I have the following
as part of my *.aspx file:
<asp:TextBox ID="txtRed" runat="server" MaxLength="3"
Width="35px">0</asp:TextBox>
And I have the following in my *.aspx.vb file:
txtRed.Attributes.Add("onchange", "if(this.value>=0&&this.value<=255){" &
redslider.ClientSetFunctionName & "(this.value);}else{this.value=" &
redslider.ClientGetFunctionName & "();}")
When my page is rendered, this comes out as the following (notice that the
&''s and < are replaced with their HTML representations):
onchange="if(this.value>=0&amp;&amp;this.value&lt; =255){sliderRed_setvalue(this.value);}else{this.va lue=sliderRed_getvalue();}"
The Server.HtmlDecode() method would not help me here because the
Attributes.Add() method takes a String as it''s second parameter, and
Server.HtmlDecode() would not have any effect on it in my case, so I would
actually be passing the same String. Any other ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OG**************@TK2MSFTNGP04.phx.gbl...

嗨Nathan,


这是HTML en / decode类。

http://msdn.microsoft.com/library/de...codeTopic1.asp

我希望这会有所帮助,

Cor


" Nathan Sokalski" < nj ******** @ hotmail.comschreef在bericht

新闻:OW ************* @ TK2MSFTNGP03.phx.gbl ...
Hi Nathan,

For that is the HTML en/decode classes.

http://msdn.microsoft.com/library/de...codeTopic1.asp

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:OW*************@TK2MSFTNGP03.phx.gbl...

>>我使用Attributes集合的Add方法向控件添加了几个JavaScript事件(onchange,onkeypress等)。但是,如果
JavaScript代码包含某些字符,例如&或者<或者其他几个,它将它们转换为html,例如& amp;或& lt;哪些可能会导致我的脚本无法正常工作。如何防止ASP.NET执行此操作?谢谢。
-
Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/




Nathan,


你确定吗你不需要这个。 (在这个页面是一个很好的样本)
http://msdn2.microsoft.com/en-us/lib...ttributes.aspx


现在你正在使用这一个添加一个属性让我们说一个列表框,其中

在我的想法中肯定不是一块javascript
http://msdn2.microsoft.com/en-us/lib...ction.add .aspx


我希望这会有所帮助,


Cor

" Nathan Sokalski" < nj ******** @ hotmail.comschreef在bericht

新闻:ew ************* @ TK2MSFTNGP04.phx.gbl ...
Nathan,

Are you sure you do not need this one. (In this page is a nice sample)
http://msdn2.microsoft.com/en-us/lib...ttributes.aspx

Now you are using this one to add an attribute let say to an listbox, which
is in my idea sure not a piece of javascript
http://msdn2.microsoft.com/en-us/lib...ction.add.aspx

I hope this helps,

Cor
"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:ew*************@TK2MSFTNGP04.phx.gbl...

如果我使用像

System.Web.UI.HtmlTextWriter这样的东西会很棒,但我只是添加了属性对象

在我的* .aspx文件中以声明方式创建。例如,我有以下

作为我的* .aspx文件的一部分:


< asp:TextBox ID =" txtRed" RUNAT = QUOT;服务器" MaxLength =" 3"

Width =" 35px"> 0< / asp:TextBox>


我的*中有以下内容。 aspx.vb文件:


txtRed.Attributes.Add(" onchange"," if(this.value> = 0&& this.value< = 255){" ;&

redslider.ClientSetFunctionName&"(this.value);} else {this.value ="&

redslider.ClientGetFunctionName&" ();}")


当我的页面被渲染时,它出现如下(注意

&'s和< ;被替换为HTML表示形式):


onchange =" if(this.value> = 0& amp;& amp; this.value& lt; = 255){ sliderRed_setvalue(this.value);} else {this.va lue = sliderRed_getvalue();}"


Server.HtmlDecode()方法对我没有帮助,因为

Attributes.Add()方法接受一个String作为它的第二个参数,并且

Server.HtmlDecode()不会有在我的情况下对它有任何影响,所以我会实际上传递相同的字符串
。还有其他想法吗?谢谢。

-

Nathan Sokalski
nj * *******@hotmail.com
http:// www.nathansokalski.com/

" Cor Ligthert [MVP]" < no ************ @ planet.nlwrote in message

news:OG ************** @ TK2MSFTNGP04.phx .gbl ...
That would be great if I were using something like the
System.Web.UI.HtmlTextWriter, but I am simply adding attributes objects
created declaratively in my *.aspx file. For example, I have the following
as part of my *.aspx file:
<asp:TextBox ID="txtRed" runat="server" MaxLength="3"
Width="35px">0</asp:TextBox>
And I have the following in my *.aspx.vb file:
txtRed.Attributes.Add("onchange", "if(this.value>=0&&this.value<=255){" &
redslider.ClientSetFunctionName & "(this.value);}else{this.value=" &
redslider.ClientGetFunctionName & "();}")
When my page is rendered, this comes out as the following (notice that the
&''s and < are replaced with their HTML representations):
onchange="if(this.value>=0&amp;&amp;this.value&lt; =255){sliderRed_setvalue(this.value);}else{this.va lue=sliderRed_getvalue();}"
The Server.HtmlDecode() method would not help me here because the
Attributes.Add() method takes a String as it''s second parameter, and
Server.HtmlDecode() would not have any effect on it in my case, so I would
actually be passing the same String. Any other ideas? Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:OG**************@TK2MSFTNGP04.phx.gbl...

>嗨Nathan,

这就是HTML en / decode类。

http://msdn.microsoft.com/library/de...codeTopic1.asp

我希望这会有所帮助,

Cor

Nathan Sokalski < nj ******** @ hotmail.comschreef在bericht
新闻:OW ************* @ TK2MSFTNGP03.phx.gbl ...
>Hi Nathan,

For that is the HTML en/decode classes.

http://msdn.microsoft.com/library/de...codeTopic1.asp

I hope this helps,

Cor

"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:OW*************@TK2MSFTNGP03.phx.gbl...

>>>我使用Attributes集合的Add方法向控件添加了几个JavaScript事件(onchange,onkeypress等)。但是,如果
JavaScript代码包含某些字符,例如&或者<或者其他几个,它将它们转换为html,例如& amp;或& lt;哪些可能会导致我的脚本无法正常工作。如何防止ASP.NET执行此操作?谢谢。
-
Nathan Sokalski
nj ******** @ hotmail.com
http://www.nathansokalski.com/





这篇关于停止Attributes.Add将我的JavaScript事件代码转换为HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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