Question regarding common class

Posted by Rocky Singh on Stack Overflow See other posts from Stack Overflow or by Rocky Singh
Published on 2011-03-18T07:45:37Z Indexed on 2011/03/18 8:09 UTC
Read the original article Hit count: 258

Filed under:
|
|

I have following two classes:

public class A : System.Web.UI.WebControls.Button
    {

        public virtual string X
        {
            get
            {
                object obj = ViewState["X"];
                if (obj != null) return (string)obj;
                return null;
            }

            set
            {
                ViewState["X"] = value;
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            X=2;
        }

    }

and

public class B : System.Web.UI.WebControls.TextBox        {

        public virtual string X
        {
            get
            {
                object obj = ViewState["X"];
                if (obj != null) return (string)obj;
                return null;
            }

            set
            {
                ViewState["X"] = value;
            }
        }


        protected override void OnLoad(EventArgs e)
        {
            X=2;
        }

    }

As you must be seeing the class A and B have exactly the same code , my question is how can I make a common class for it and use these two classes.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET