Home
Browse all 647 examples
Download all 647 examples
Download sample chapters
Reviews
Errata
Acknowledgments
Links on .NET
Paradoxal Press

Buy directly from Paradoxal Press at $33.99 (Save 43%)



Category: Programming
Level: Beginner to seasoned
900 pages
ISBN-10 097661322-0
ISBN-13 978-097661322-0
$59.99 USA
$79.99 CANADA


Listing 23-41 extracted from chapter ASP.NET 2


Listing 23-40<     > Listing 23-42


This listing can be compiled with the command line:
csc.exe /out:MyUserCtrl.dll /target:library Example_23_41_to_rename_MyUserCtrl.cs
Errors: 0 Warnings: 0


Example_23_41_to_rename_MyUserCtrl.cs
using System.Web.UI;
namespace MyUserCtrls {
   public class MyUserCtrl : Control {
      private string m_Color;
      public string Color { get{return m_Color;set{ m_Color=value;} }
      private string m_Text;
      public string Text { get{return m_Text;set{ m_Text=value;} }
      protected override void OnInit(System.EventArgs e) {
         Page.RegisterRequiresControlState(this);
         base.OnInit(e);
      }
      protected override object SaveControlState() {
         object[] state = new object[2];
         state[0= m_Color;
         state[1= m_Text;
         return state;
      }
      protected override void LoadControlState(object _state) {
         if (_state != null) {
            object[] state = _state as object[];
            if (state[0] != null) m_Color = state[0as string;
            if (state[1] != null) m_Text = state[1as string;
         }
      }
      protected override void Render(HtmlTextWriter writer) {
         writer.Write("<p><font color=\"" + m_Color +
                      "\">" + m_Text + "</font></p>");
      }
   }
}	
Copyright Patrick Smacchia 2006 2007