As I said a couple of days ago, I'm doing a bunch of work on my blog code. One of the things I wanted to have was an integrated Newsgator ratings system.
It turns out that it isn't all that hard to do, provided you have access to your skin's source files (sorry to those of you on hosted .TEXT sites--ask your blog admin to add this control for you).
To get this working you need to create a new .ASCX file in your skin's Controls directory. Put the following code into it (sorry for all the funny line breaks... I wanted it to fit in my blog... reformat it as you see fit). Note: you have to split up the "<" from the "script>" part or the ASP.NET parser won't compile correctly.
1: <%@ Control Language="c#"
2: Inherits="Dottext.Web.UI.Controls.BaseControl" %>
3: <%@ Import Namespace="Dottext.Framework.Components" %>
4: <%@ Import Namespace="Dottext.Common.Data" %>
5:
6: <script runat=server>
7: private Entry entry;
8:
9: void Page_Load(object sender, System.EventArgs e)
10: { 11: if( entry == null )
12: entry = Cacher.GetEntryFromRequest(Context,CacheTime.Short);
13:
14: string url = CurrentBlog.UrlFormats.EntryUrl(entry);
15: ratingsLiteral.Text = String.Format("<" + "script " + 16: "src=\"http://www.newsgator.com/ngs/ratings.aspx?rurl={0}\"><" + 17: "/script>", url);
18: }
19:
20: public Entry Entry
21: { 22: get { return entry; } 23: set { entry = value; } 24: }
25: </script>
26:
27: Rating: <asp:Literal Runat=server ID=ratingsLiteral></asp:Literal>
Now to use it in your blog, you need to add this control to some of the existing ASCX files. I'll demonstrate two for you and let you figure out the rest on your own.
Here is my new Day.ascx file:
1: <%@ Control Language="c#" Inherits="Dottext.Web.UI.Controls.Day" %>
2: <%@ Register TagPrefix="uc1" TagName="Ratings" Src="Ratings.ascx" %>
3: <%@ Import Namespace = "Dottext.Framework.Components" %>
4: <p class="date">
5: <asp:Literal ID = "DateTitle" Runat = "server" />
6: <asp:HyperLink Runat="server" Title = "Day Archive" Text = "#"
7: height="15" Width="12" BorderWidth="0" ID="ImageLink" />
8: </p>
9:
10: <asp:Repeater runat="Server" Runat="server" ID="DayList"
11: OnItemCreated="PostCreated">
12:
13: <ItemTemplate>
14: <div class="post">
15: <h2><asp:HyperLink Runat="server" ID="TitleUrl" /></h2>
16:
17: <asp:Literal runat="server" ID="PostText" />
18:
19: <p class="postfoot">
20: <asp:Literal ID = "PostDesc" Runat = "server" />
21: |
22: <uc1:Ratings runat=server id=ratings1
23: Entry="<%# (Entry)Container.DataItem %>"></uc1:Ratings>
24: </p>
25: </div>
26: </ItemTemplate>
27: </asp:Repeater>
Notice how I got the Entry out of the Repeater. Now lets look at my ViewPost.ascx file (which doesn't have a Repeater):
1: <%@ Control Language="c#" Inherits="Dottext.Web.UI.Controls.ViewPost" %>
2: <%@ Register TagPrefix="uc1" TagName="Ratings" Src="Ratings.ascx" %>
3: <div class="post">
4: <h2>
5: <asp:HyperLink Runat="server" ID="TitleUrl" />
6: </h2>
7: <asp:Literal id="Body" runat="server" />
8: <p class="postfoot">
9: posted on <asp:Literal id="PostDescription" runat="server" />
10: <br/>
11: <uc1:Ratings runat=server id=ratings1></uc1:Ratings>
12: </p>
13: </div>
14: <asp:Literal ID = "PingBack" Runat = "server" />
15: <asp:Literal ID = "TrackBack" Runat = "server" />
16:
If you look back up in the control, you'll see that if you haven't set the Entry property, it attempts to load it from the Request.
This code doesn't have a lot of error checking in it at this point, but it illustrates the point.
Enjoy!
Now playing: Jimi Hendrix - I Don't Live Today