By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,444 Members | 3,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,444 IT Pros & Developers. It's quick & easy.

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

P: n/a
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;
}
}
}

Oct 19 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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)

Joshua wrote:
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;
}
}
}
Oct 19 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.