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