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

J

Joshua

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;
}
}


}
 
B

bruce barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top