using System;
using System.Text;
namespace DPLib
{
/// <summary>
/// Provides design-time display of the ClientScripts ASP.Net control
/// </summary>
public class ClientScriptsDesigner : System.Web.UI.Design.ControlDesigner
{
/// <summary>
/// Displays a list of scriptEnabled client scripts
/// </summary>
/// <returns></returns>
public override string GetDesignTimeHtml()
{
// Create an instance of the component being designed
ClientScripts cScripts = (ClientScripts) Component;
// A StringBuilder to return the design-time display HTML.
StringBuilder sb = new StringBuilder();
StringBuilder sbClient = new StringBuilder();
StringBuilder sbStartup = new StringBuilder();
sb.Append("<div style=\"color=black; background-color=silver\"><B>Client Scripts:</B>");
// Loop through the scripts and add each scriptEnabled script to the design-time display
foreach (ClientScript script in cScripts.Scripts)
{
string alert = (script.ScriptUrl.Trim().Length == 0)
? "<font size=4 color=red>*</font>"
: string.Empty;
if (script.ScriptEnabled && script.ScriptType == ScriptTypes.ClientScript)
{
// Add to the ClientScript StringBuilder
sbClient.Append(script.ID + alert + "<BR>");
}
else if (script.ScriptEnabled)
{
// Add to the StartupScript StringBuilder
sbStartup.Append(script.ID + alert + "<BR>");
}
}
// If there are no ClientScript objects, then display <Empty>
if (sbClient.Length == 0)
{
sbClient.Append("<center><Empty></center>");
}
else
{
sb.Append("<BR>");
}
sb.Append(sbClient.ToString());
// Render the design-time view of the StartupScript ClientScript objects.
sb.Append("<B>Startup Scripts:</B>");
// If there are no StartupScript objects, then display <Empty>
if (sbStartup.Length == 0)
{
sbStartup.Append("<center><Empty></center>");
}
else
{
sb.Append("<BR>");
}
sb.Append(sbStartup.ToString());
sb.Append("</div>");
// Return the HTML to display in the design-time environment
return sb.ToString();
}
}
}