CMS2002: Image, ImageButtons, and How to Add Redirects
It’s thumbnail madness this week, it appears. I keep running into odd things regarding thumbnails and redirection. Today it’s not specifically opening a new window, and it’s not ASP.NET 2.0. We’re looking at good old ASP.NET 1.1, Microsoft CMS 2002, and attempting to get a posting’s associated image (which we have a thumbnail of on the home page) to redirect the visitor to the news posting when clicked.
My original idea? An image with an onclick attribute. Nope! Images don’t have an onclick event.
So the solution? A not-as-fancy literal!
Note: This assumes that you have instanciated your environment accordingly. ThisPosting is a singular posting that is part of a PostingCollection called Postings. MaxHeight and MaxWidth are variables contained in the web.config file.
The first thing we need to do is grab the ImagePlaceholder from the template:
SummaryImage = (ImagePlaceholder)ThisPosting.Placeholders[“SummaryImage”]
Now, let’s create our Literal control. We’re creating a control rather than a simple String because we’ll later use the Controls.Add to place it. If you are simply rendering it out, a String would work.
Literal postingImage = new Literal();
postingImage.Text = “<a href='” + url + “‘ border=’0’><img src='” + SummaryImage.Src + “‘ width='” + MaxWidth.ToString() + “‘ height='” MaxHeight.ToString() + “‘ border=’0’></a>”;
Now, as I stated, my news postings are rendered out into a table. We need to add this new control to our TableCell cell. To do this, a simple Controls.Add works.
cell = new TableCell();
cell.HorizontalAlign = HorizontalAlign.Left;
cell.VerticleAlign = VerticalAlign.Top;
cell.CssClass = “summary”;
From here, I have a table called tblSummary that the cell created above will be placed into.