S
shapper
Hello,
I have an Action where I define a ViewData property named Ad:
public ActionResult GoogleAdSense(string client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder();
ad.AppendLine("<script type='text/javascript'>");
ad.AppendLine("<!--");
ad.AppendLine(String.Concat("google_ad_client = '", client,
"';"));
ad.AppendLine(String.Concat("google_ad_slot = '", slot, "';"));
ad.AppendLine(String.Concat("google_ad_width = ",
width.ToString(), ";"));
ad.AppendLine(String.Concat("google_ad_height = ",
height.ToString(), ";"));
ad.AppendLine("//--> ");
ad.AppendLine("</script>");
ad.AppendLine("<script type='text/javascript' src='http://
pagead2.googlesyndication.com/pagead/show_ads.js'></script>");
ViewData["Ad"] = ad;
return View("GoogleAdSense");
}
Then I use, on the control:
<%= Html.Encode(ViewData["Ad"]) %>
This is not working because I get in my Page Source:
<script type='text/javascript'>
<!--
google_ad_client = '###########';
google_ad_slot = '######';
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type='text/javascript' src='http://
pagead2.googlesyndication.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(string client, int height,
string slot, int width) {
StringBuilder ad = new StringBuilder();
ad.AppendLine("<script type='text/javascript'>");
ad.AppendLine("<!--");
ad.AppendLine(String.Concat("google_ad_client = '", client,
"';"));
ad.AppendLine(String.Concat("google_ad_slot = '", slot, "';"));
ad.AppendLine(String.Concat("google_ad_width = ",
width.ToString(), ";"));
ad.AppendLine(String.Concat("google_ad_height = ",
height.ToString(), ";"));
ad.AppendLine("//--> ");
ad.AppendLine("</script>");
ad.AppendLine("<script type='text/javascript' src='http://
pagead2.googlesyndication.com/pagead/show_ads.js'></script>");
ViewData["Ad"] = ad;
return View("GoogleAdSense");
}
Then I use, on the control:
<%= Html.Encode(ViewData["Ad"]) %>
This is not working because I get in my Page Source:
<script type='text/javascript'>
<!--
google_ad_client = '###########';
google_ad_slot = '######';
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type='text/javascript' src='http://
pagead2.googlesyndication.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