Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

Override Text and Visible in System.Web.UI.UserControl

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joshua - 19 Oct 2007 22:21 GMT
I'm creating a web control that has an image and a text box.  I would
like to then override the Visible and Text property of the
usercontrol, so when you reference the visible property of the user
control it only set the visible property of the textbox.

When i call these newly created property I get the following error:

Object reference not set to an instance of an object.

Does anybody have any idea?  Thank you.

Here is the code:

public abstract class DateSelector : System.Web.UI.UserControl
    {
        //protected System.Web.UI.WebControls.Label lbl_Date;
        protected System.Web.UI.WebControls.TextBox txt_Date;
        protected System.Web.UI.WebControls.Image imgCalendar;

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            string scriptStr = "javascript:return popUpCalendar(this," +
getClientID() + @", 'mm/dd/yyyy', '__doPostBack(\'" + getClientID() +
@"\')')";
            imgCalendar.Attributes.Add("onclick", scriptStr);
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            InitializeComponent();
            base.OnInit(e);
        }
        private void InitializeComponent()
        {
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        public string getClientID()
        {
            return txt_Date.ClientID;
            }

        public string Text
        {
            get
            {
                return txt_Date.Text;
            }
            set
            {
                txt_Date.Text = value;
            }
        }

       public override virtual bool Visible
       {
           get
           {
               return imgCalendar.Visible;
           }
           set
           {
               imgCalendar.Visible = value;
           }
       }

    }
bruce barker - 20 Oct 2007 00:33 GMT
this won't work. if your control is set to invisible, then its render
routine is not called. you should make a new property.

anyway the bug is your setting a property of one of your children, but
its not created yet. call ensurechildren first.

-- bruce (sqlwork.com)

> I'm creating a web control that has an image and a text box.  I would
> like to then override the Visible and Text property of the
[quoted text clipped - 67 lines]
>
>     }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.