ASP.NET Wrapper - Custom DOCTYPE for a wrapped control

From Visual WebGui Wiki

Jump to: navigation, search

Contents

Overview

Some wrapped ASP.NET controls will require a different DOCTYPE settings, compared to what is the default DOCTYPE in your Visual WebGui application. What DOCTYPE is required for each type of control may vary, and you need to consult the control's documentation to find out. The symptoms you will experience when specifying the wrong DOCTYPE for any control will also vary, some will not fully work, some will render incorrectly etc. The most common requirement is that an XHTML DOCTYPE must be used for the control, which is not the default for Visual WebGui application.

This article will tell you about the purpose of DOCTYPE settings in in Html rendering, list some of the most common DOCTYPE settings and their purpose, and finally we will demonstrate how you can have a different/custom DOCTYPE for your whole application, for wrapped ASP.NET controls in general or for individual controls.

The purpose of DOCTYPE

The purpose of DOCTYPE is to tell the client browser what Html standard is being used in the Html that follows. Setting the DOCTYPE is almost like signing a contract, where you promise that all the Html that follows will adhere to a specific standard.

The DOCTYPE tag is an optional tag for an Html document, but if it needs to be set, it must be the first tag rendered in the document. DOCTYPE tags rendered later in the document, not as the first tag, will have no effect.

Some common DOCTYPE settings

<!-- Common Html DOCTYPE -->
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN">
<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 
<!-- Common XHTML DOCTYPE -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 
<!-- HTML5 DOCTYPE -->
<!DOCTYPE html>

Currently, Visual WebGui applications use the first DOCTYPE in the list above.

More DOCTYPE declarations can be found in the WikiPedia Quirks mode article.

DOCTYPE in Visual WebGui

In Visual WebGui, the DOCTYPE is set by the currently active Theme and is global for the application. For wrapped ASP.NET controls, the DOCTYPE will be set according to the global DOCTYPE of the application, or in other words, each wrapped ASP.NET control will by default inherit the application default DOCTYPE setting.

Options for custom DOCTYPE

Custom DOCTYPE globally for the application

You can override the DOCTYPE globally for your Visual WebGui application, which will then render that new DOCTYPE for your wrapped controls. This may be undesirable, as changing the DOCTYPE globally can affect the Visual WebGui application itself, as it has been tested only for the current default DOCTYPE. For this you will need to create a custom Theme and override Common.Dialogs.Main.*.htm Html documents to change the DOCTYPE inside of those files. More on Themes.

Custom DOCTYPE for wrapped ASP.NET controls

To change the DOCTYPE for wrapped controls, you will need a PageAdapter and override the BeginRender method, as the DOCTYPE must be the absolutely first attribute rendered for your controls, otherwise it will not be effective. For this purpose you will need to perform the following steps:

  1. Create a PageAdapter class file and override the BeginRender method (see code below)
  2. Create an ASP.NET App_Browsers folder in your application.
  3. Create a browser file on this new folder, registering custom PageAdapter for your control(s).

Typical PageAdapter class file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
 
using System.Web.UI;
using System.Web.UI.Adapters;
namespace TestGrid
{
    public class InfragisticsPageAdapter : PageAdapter 
    {
        protected override void BeginRender(HtmlTextWriter writer)
        {
            writer.WriteLine(@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">");
            base.BeginRender(writer);
        }
    }
}

Typical browser file

<!--
    You can find existing browser definitions at
    <windir>\Microsoft.NET\Framework\<ver>\CONFIG\Browsers
-->
<browsers>
  <browser refID="Default">
    <controlAdapters>
      <adapter
        controlType="System.Web.UI.Page"
        adapterType="TestGrid.InfragisticsPageAdapter"
      />
    </controlAdapters>
  </browser>
</browsers>

See also

Forum discussions

References

Personal tools