Create AdSense Widget

Topics: Controls
Jan 2, 2010 at 1:34 PM

steps to creating a widget to show adsense ads in a widget.

1.Create Adsense folder under widgets folder.

2. Create widget.ascx file

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="widget.ascx.cs" Inherits="widgets_Adsense_AdSense" %>

<div id="newsletterform">

<script type="text/javascript"><!--

google_ad_client = "pub-1069152880332427";

/* blog 120x600, created 9/22/08 */

google_ad_slot = "8463252391";

google_ad_width = 120;

google_ad_height = 600;

//-->

</script>

<script type="text/javascript"

src="http://pagead2.googlesyndication.com/pagead/show_ads.js">

</script>

</div>

add code below to widget.ascx.cs file

using System;

using System.Configuration;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.HtmlControls;

public partial class widgets_Adsense_AdSense : WidgetBase

{

public override string Name

{

get { return "Ads by Google"; }

}

public override bool IsEditable

{

get { return false; }

}

public override void LoadWidget()

{

Visible = true;

}

}

save files.

load web site and you should see AdSense in the widget dropdown list .