473,396 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
1 3054
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Tee | last post by:
Hi, I have a usercontrol with a overridable/virtual method. On the usercontrol onload, it will call this method. Now I have a form that have a few of this usercontrol. And I want to override...
0
by: DotNetBBK | last post by:
Hi, I am using a custom text box, where I need to override TabSelection, as I have to generate an event and based on that event, I need to do some processing in other class, who is listening to...
0
by: Diego | last post by:
Hallo! I have an HtmlTable with a UserControl into it. Setting table.Visible = false all controls in table have .Visible = false. Then, setting table.Visible = true all controls in table except...
0
by: Syed Zaidi via .NET 247 | last post by:
I am working on a small project in which i want to develop acustom toolbar skeleton for handling database navigation. I havecreated a usercontrol consist of a toolbar inherits fromusercontrol and...
2
by: Syed Zaidi | last post by:
Hello All I am a newbie in VB.NET and wanting to create a toolbar(User Control) for Database Navigation. What exactly I want is to have a user control which is inherited from the...
6
by: Marc Robitaille | last post by:
Hello, Hello, I developed a UserControl. It has funny behavior. It is composed of three controls. A texbox, a combobox and a button. There are three properties to indicate the visibility of...
2
by: David Veeneman | last post by:
I'm having trouble implementing a UserControl base property in a user control that I am writing. My user control wraps a group box that contains several radio buttons. I want to wire the user...
5
by: Dom | last post by:
I have a usercontrol, and I am trying to write a Property called "Text", but the compiler tells me that the Usercontrol class already has a member called "Text". When I look (in intellisense, or...
2
by: Maddy | last post by:
I need to populate a treeview from a text file. The data in it is in the following form 1. (Parent Node) (a) (Child Node) (b) (Child Node) .. .. .. (k) (Child Node)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.