Tags

,

Today I spent time on change the css for a custom control, read a good post by Scott Gu on http://weblogs.asp.net/scottgu/archive/2006/05/02/CSS-Control-Adapter-Toolkit-for-ASP.NET-2.0-.aspx

So I start in vs 2008,

using System.Web.UI;
using System.Web.UI.Adapters;

namespace NameSpace{
    public class MyControlAdapter : System.Web.UI.WebControls.Adapters.DataBoundControlAdapter
    {
         Example showing override of Render to control entire rendering
        protected override void Render(HtmlTextWriter writer)
        {
            //Style s = new Style();
            //s.ForeColor = System.Drawing.Color.Red;
            //writer.EnterStyle(s);
            //writer.Write(“Welcome custom control adapter.”);
            //writer.ExitStyle(s);
            writer.RenderBeginTag(HtmlTextWriterTag.Div);
            base.Render(writer);
            writer.RenderEndTag();
        }
         Additional implementation
        protected override void RenderBeginTag(HtmlTextWriter writer)
        {
            writer.WriteBeginTag(“p”);
            writer.WriteAttribute(“class”,”knowledge_cloud”);
            writer.Write(HtmlTextWriter.TagRightChar);
            writer.WriteBeginTag(“div”);
            writer.WriteAttribute(“class”, “tag_cloud”);
            writer.Indent++;
        }

        protected override void RenderEndTag(HtmlTextWriter writer)
        {
            writer.WriteEndTag(“div”); ;
        }
    }
}

and you need create a browser file in the solution

<!–
    You can find existing browser definitions at
    <windir>\Microsoft.NET\Framework\<ver>\CONFIG\Browsers
–>
<browsers>
    <browser id=”NewBrowser” parentID=”Mozilla”>
        <identification>
            <userAgent match=”Unique User Agent Regular Expression” />
        </identification>
     
      <controlAdapters>
        <adapter controlType=”Readify.KnowledgeInputs.Web.Controls.KnowledgeEventTagCloud” adapterType=”Readify.ConsultantPortal.Web.App_Code.MyControlAdapter” />
      </controlAdapters>
     
        <capture>
            <userAgent match=”NewBrowser (?’version’\d+\.\d+)” />
        </capture>

        <capabilities>
            <capability name=”browser” value=”My New Browser” />
            <capability name=”version” value=”${version}” />
        </capabilities>
    </browser>

    <browser refID=”Mozilla”>
        <capabilities>
            <capability name=”xml” value=”true” />
        </capabilities>
      <controlAdapters>
        <adapter controlType=”NameSpace.KnowledgeEventTagCloud” adapterType=”NameSpace.MyControlAdapter” />
      </controlAdapters>
    </browser>
</browsers>

so the part

<adapter controlType=”NameSpace.KnowledgeEventTagCloud” adapterType=”NameSpace.MyControlAdapter” />

will call your controladapter to do some magic

Advertisements