0

I want to achieve functionality to store adsense code into sql database. For that I have used ajax:HtmlEditorExtender on a textbox. now I am typing this code

<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>

now the problem is when the code is inserted to database, above code is converted as below.

    &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;

Please help me out:

  1. what should I do so that i can store the upper code as it is to database.
  2. when the code is properly stored to database, which control is best suitable to show this ad.(I mean I want to show ad on another page.)

Thanks in advance.

3
  • 1
    Are you using the sanitizer? Just making sure. Why not use ckeditor? Commented Aug 7, 2013 at 7:59
  • @PaulZahra : using EnableSanitization="true" resolves my first problem. Thanks a lot. what should i do for my second problem. Commented Aug 7, 2013 at 8:08
  • @PaulZahra sorry for my blunder. using EnableSanitization="true" doesn't make difference. This is also surrounding <span> to each text like this. <span style="font&#x2D;size&#x3A;&#x20;18&#x2E;88888931274414px&#x3B;">script</span> Commented Aug 7, 2013 at 8:51

1 Answer 1

1

RE issue2: You could use a normal textbox and just decode the string, or put it back into a ajax:HtmlEditorExtender textbox, and use the following code (sanitizer has probably encoded all the tag start and ends etc...

Server.HtmlDecode(TextBox_Editor.Text)

In response to your comment: Try putting the decoded text into a asp:label OnPreRender

EDIT: Try using HtmlAgilityPackSanitizerProvider, the latest pack which resolves some 'bugs' surrounding the sanitizer... have a read of this page, by Stephen Walters own admission the default sanitizer is far too aggressive in what it strips.

Sign up to request clarification or add additional context in comments.

2 Comments

I think u got me wrong. Actually I want to display the ad on different page, whose adsense-code comes from the database. So which control I should use so that retrieved code can displayed as ad.
thanks @PaulZahra the approach u suggested is really helping. thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.