SiteExperts.com Logo Home | Community | Developer's Paradise | Jobs
User Groups | Site Tools | Site Information | Search

Inside Technique : Cool Rules : Server-side Generation

We found the most reliable way to create rules was to generate them on the server. We recognized that the same createHR() function we execute on the client can execute unchanged on the server. Now, when the client receives the page, they just receive the table populated with the correct colors.

Moving to the server only required modifying the single line of script that inserts the table into the page. We changed the document.write() method to the server-side equivalent. The client-side rule is generated as follows:

<SCRIPT>
  document.write(createHR("000000","FFFFFF",32,"150",3, true, false, "center"))
</SCRIPT>

The equivalent call to create this on the server with an ASP file is:

<%=createHR("000000","FFFFFF",32,"150",3, true, false, "center") >

When it comes to using this code, we highly recommend the server solution over the client-side solution. When server-side scripting is not an option, another alternative is to use the function to generate the table string, and then copy the string directly into your document. In reality, inserting the generating table gives you the best performance, but also makes it more difficult to later customize the rule.

Guidelines

Before showing you the code, there are a couple guidelines you should keep in mind when building a rule:

  1. The more steps, the longer it takes to create the rule.
  2. Always make sure the steps is smaller than the width for horizontal rules and smaller than the height for vertical rules. We have noticed that anymore than 64 steps is usually overkill especially considering the first rule.
  3. Sometimes the colors do not blend correctly due to rounding errors. Try changing the number of steps when this occurs.

On the last page is the actual source code. This code can run on either the client or server without modification.