2013-08-07 38 views
0

我想实现将adsense代码存储到sql数据库的功能。为此,我在文本框上使用了ajax:HtmlEditorExtender。现在我打字这个代码如何从文本框中获取javascript/html代码

<script type="text/javascript"><!-- google_ad_client = "ca-pub-*****"; /* 728x90, created 6/12/02 */ google_ad_slot = "****"; google_ad_width = 728; google_ad_height = 90; //--> </script> <script type="text/javascript" src="http://pagead.googlesyndicaon.com/pead/show_ad.js"> </script> 

现在当代码被插入到数据库中,上述代码被如下转换的问题是。

&lt;pre&gt;&lt;<span>script</span> <span>type</span>="<a>text/javascript</a>"&gt;&lt;!-- 
    <span></span>google_ad_client = "ca-pub-*****"; 
    <span></span>/* 728x90, created 6/12/02 */ 
    <span></span>google_ad_slot = "****"; 
    <span></span>google_ad_width = 728; 
    <span></span>google_ad_height = 90; 
    <span></span>//--&gt; 
    <span></span>&lt;/<span>script</span>&gt; 
    <span></span>&lt;<span>script</span> <span>type</span>="<a>text/javascript</a>" 
    <span></span><span>src</span>="<a href="view-source:http://pagead.googlesyndicaon.com/pead/show_ad.js"> 
http://pagead.googlesyndicaon.com/pead/show_ad.js</a>"&gt; 
    <span></span>&lt;/<span>script</span>&gt;&lt;/pre&gt; 

请帮我:

  1. 我应该做的,这样我可以存储上的代码,因为它是数据库。
  2. 当代码正确存储到数据库中,这是控制最适合显示广告。(我的意思是我想告诉另一页上的广告。)

在此先感谢。

+1

你在使用洗手液吗?只要确定。为什么不使用ckeditor? –

+0

@PaulZahra:使用EnableSanitization =“true”可以解决我的第一个问题。非常感谢。我应该为我的第二个问题做些什么。 –

+0

@PaulZahra对不起我的错误。使用EnableSanitization =“true”并没有什么区别。这也是围绕这样的每个文本。 脚本

回答

1

RE问题2:您可以使用正常的文本框,只需解码字符串,或将其放回到ajax:HtmlEditorExtender文本框中,并使用以下代码(清洁工可能编码了所有标签的开始和结束等等...

Server.HtmlDecode(TextBox_Editor.Text) 

在回答您的评论:尝试将解码后的文成ASP:标签的OnPreRender

编辑:尝试使用HtmlAgilityPackSanitizerProvider,从而解决了一些“错误”周围的消毒液的最新包...有阅读this page,斯蒂芬沃尔特斯自己承认,默认的杀菌剂太过侵略了在它剥夺的东西。

+0

我想你让我错了。实际上,我想在不同的网页上展示广告,其AdSense代码来自数据库。那么我应该使用哪个控件,以便检索的代码可以显示为广告。 –

+0

感谢@PaulZahra你建议的方法真的有帮助。再次感谢。 –

相关问题