Hello,
I have an Action where I define a ViewData property named Ad:
public ActionResult GoogleAdSense(s tring client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder() ;
ad.AppendLine(" <script type='text/javascript'>");
ad.AppendLine(" <!--");
ad.AppendLine(S tring.Concat("g oogle_ad_client = '", client,
"';"));
ad.AppendLine(S tring.Concat("g oogle_ad_slot = '", slot, "';"));
ad.AppendLine(S tring.Concat("g oogle_ad_width = ",
width.ToString( ), ";"));
ad.AppendLine(S tring.Concat("g oogle_ad_height = ",
height.ToString (), ";"));
ad.AppendLine("//--");
ad.AppendLine(" </script>");
ad.AppendLine(" <script type='text/javascript' src='http://
pagead2.googles yndication.com/pagead/show_ads.js'></script>");
ViewData["Ad"] = ad;
return View("GoogleAdS ense");
}
Then I use, on the control:
<%= Html.Encode(Vie wData["Ad"]) %>
This is not working because I get in my Page Source:
<script type='text/javascript'>
<!--
google_ad_clien t = '###########';
google_ad_slot = '######';
google_ad_width = 300;
google_ad_heigh t = 250;
//-->
</script>
<script type='text/javascript' src='http://
pagead2.googles yndication.com/pagead/show_ads.js'> ;</script>
The problem is with the '<' and '>' characters. Any idea why?
One more question: in C# when I want a quote inside a "" should I use
' ?
The generated code shows ' but in Google Ad Sense they say to use ".
I tried to use "" to create a " but I get an error on my code. Why?
Thanks,
Miguel
I have an Action where I define a ViewData property named Ad:
public ActionResult GoogleAdSense(s tring client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder() ;
ad.AppendLine(" <script type='text/javascript'>");
ad.AppendLine(" <!--");
ad.AppendLine(S tring.Concat("g oogle_ad_client = '", client,
"';"));
ad.AppendLine(S tring.Concat("g oogle_ad_slot = '", slot, "';"));
ad.AppendLine(S tring.Concat("g oogle_ad_width = ",
width.ToString( ), ";"));
ad.AppendLine(S tring.Concat("g oogle_ad_height = ",
height.ToString (), ";"));
ad.AppendLine("//--");
ad.AppendLine(" </script>");
ad.AppendLine(" <script type='text/javascript' src='http://
pagead2.googles yndication.com/pagead/show_ads.js'></script>");
ViewData["Ad"] = ad;
return View("GoogleAdS ense");
}
Then I use, on the control:
<%= Html.Encode(Vie wData["Ad"]) %>
This is not working because I get in my Page Source:
<script type='text/javascript'>
<!--
google_ad_clien t = '###########';
google_ad_slot = '######';
google_ad_width = 300;
google_ad_heigh t = 250;
//-->
</script>
<script type='text/javascript' src='http://
pagead2.googles yndication.com/pagead/show_ads.js'> ;</script>
The problem is with the '<' and '>' characters. Any idea why?
One more question: in C# when I want a quote inside a "" should I use
' ?
The generated code shows ' but in Google Ad Sense they say to use ".
I tried to use "" to create a " but I get an error on my code. Why?
Thanks,
Miguel
Comment