๐Ÿงฐ Common ASP References (Shared)
Estimated reading: 3 minutes 296 views

ASP โ€“ Content Rotator โ€“ Display Randomized Text or HTML in Classic ASP

Introduction โ€“ What Is the ASP Content Rotator?

The ASP Content Rotator is a simple, classic ASP tool that allows developers to randomly rotate chunks of contentโ€”like quotes, ads, or tipsโ€”on a webpage. Unlike the Ad Rotator (which is image-based), the Content Rotator focuses on text or HTML block rotation using a text-based configuration file.

In this guide, youโ€™ll learn:

  • How the Classic ASP Content Rotator works
  • How to format the content rotation file
  • Embed randomized HTML/text content into your ASP pages
  • Best practices and real output examples

How It Works โ€“ The .txt Content File Format

The Content Rotator uses a special text file that separates each content block with a line starting with "%%".

Sample rotate.txt:

%%  
<b>Tip:</b> Press CTRL+S to save your work regularly.  
%%  
<b>Fun Fact:</b> ASP stands for Active Server Pages.  
%%  
<b>Reminder:</b> Clear your browser cache weekly.

Classic ASP Example โ€“ Using ContentRotator

<%
Set obj = Server.CreateObject("MSWC.ContentRotator")
Dim result
result = obj.ChooseContent(Server.MapPath("rotate.txt"))
Response.Write result
%>

Output Example (Random):

<b>Fun Fact:</b> ASP stands for Active Server Pages.

MSWC.ContentRotator is a COM component built into Classic ASP/IIS.


Where to Store the .txt File

  • Place it in a secure, read-accessible folder like /includes/rotate.txt
  • Use Server.MapPath() to convert the relative path to an absolute one

HTML Integration โ€“ Embed into Any Page

<div class="rotator">
    <% =obj.ChooseContent(Server.MapPath("rotate.txt")) %>
</div>

Rotate promotional content, quotes, customer testimonials, or announcements.


How Rotation Works

  • Random entry is chosen on every page load
  • Entries are separated by "%%" markers
  • Only one block is selected at a time

Best Practices for ASP Content Rotator

Do:

  • Escape quotes (") inside content or use single quotes (')
  • Use Server.MapPath() to avoid broken path errors
  • Limit content size in each block for faster rendering

Avoid:

  • Mixing it with binary content (itโ€™s for HTML/text only)
  • Including script tags unless carefully managed
  • Dynamically writing to the rotation file (causes conflicts)

Summary โ€“ Recap & Next Steps

The ASP Content Rotator is a great way to add variation to static content without JavaScript or a database. It’s ideal for random messages, tips, or notifications that enhance user engagement with minimal setup.

Key Takeaways:

  • Use MSWC.ContentRotator with a rotate.txt file
  • Separate content with "%%" to define entries
  • Display random text or HTML blocks on page load

Real-world Use Cases:

  • Daily tips, coding quotes, marketing slogans
  • Testimonials and client feedback display
  • Educational platforms for rotating practice questions

FAQs โ€“ ASP Content Rotator


What format does the content file require?
Each entry must be separated by a line containing only %%.


Can I use HTML inside the rotation entries?
Yes! You can add <b>, <p>, <a>, and other HTML tags.


Does it rotate per session or per page load?
It rotates per page load, not per session.


Share Now :
Share

๐Ÿ”„ ASP โ€“ Content Rotator

Or Copy Link

CONTENTS
Scroll to Top