DCSIMG
ASP.NET 2 Custom Control for Google "UrchinTracker" as sample - Client-Side with Basil Goldman

ASP.NET 2 Custom Control for Google "UrchinTracker" as sample


Simple example to create ASP.NET 2 Custom Control for Google "UrchinTracker"

1) Edit Web.config file add the next code between <system.web>

<pages>
     <controls>
          <add namespace="Render.Web.UI.CustomControls" assembly="App_Code" tagPrefix="render" />
     </controls>
</pages>

2) Create a new class file *.cs in App_Code/Render/Web/UI/CustomControls

using System;

using System.Web.UI;

using System.Text;

using System.Web.UI.WebControls;

 

/// <summary>

/// Summary description for UrchinTracker

/// </summary>

namespace Render.Web.UI.CustomControls {

 

    // Inherit Control

    public class UrchinTracker : Control {

 

        #region Fields

        private string userAccount;

        #endregion

 

        #region Properties

        public string UserAccount {

            get { return userAccount; }

            set { userAccount = value; }

        }

        #endregion

 

        #region Constructor

        public UrchinTracker() {

            //

            // TODO: Add constructor logic here

            //

        }

        #endregion

 

        public string GetOutput() {

            StringBuilder output = new StringBuilder();

            if (!String.IsNullOrEmpty(UserAccount)) {

                output.AppendFormat(

@"<script src="" mce_src=""http://www.google-analytics.com/urchin.js"" type=""text/javascript""></script>

<script type=""text/javascript"">

_uacct = ""{0}"";

urchinTracker();

</script>

", UserAccount);

 

            }

           

            return output.ToString();

        }

 

        protected override void Render(HtmlTextWriter writer) {

            writer.Write(GetOutput());

            base.Render(writer);

        }

    }

}

3) Build project then add control to ASP.NET Page

<render:UrchineTracker ID="UrchineTracker1" UserAccount="1234567890" runat="server" />

Using this example you can create riched, and advanced Custom Controls for you projects.

I'm working at this time on the package of custom controls for ASP.NET 2 & WPF to make it easy our development live...
The Beta comming up... in Mar 2008

Comments

No Comments

Leave a Comment

(required) 
(required) 
(optional)
(required) 

Enter the numbers above: