Click here to Skip to main content
15,925,181 members
Home / Discussions / C#
   

C#

 
GeneralRe: Transparency (like Rainlendar) Pin
jgallen231-Feb-06 20:58
jgallen231-Feb-06 20:58 
GeneralRe: Transparency (like Rainlendar) Pin
Dave Kreskowiak2-Feb-06 1:54
mveDave Kreskowiak2-Feb-06 1:54 
QuestionQuick Threading Question Pin
Mr. Rogers1-Feb-06 13:02
Mr. Rogers1-Feb-06 13:02 
AnswerRe: Quick Threading Question Pin
S. Senthil Kumar1-Feb-06 13:21
S. Senthil Kumar1-Feb-06 13:21 
GeneralRe: Quick Threading Question Pin
Mr. Rogers1-Feb-06 13:33
Mr. Rogers1-Feb-06 13:33 
GeneralRe: Quick Threading Question Pin
Mark Greenwood1-Feb-06 13:54
Mark Greenwood1-Feb-06 13:54 
GeneralRe: Quick Threading Question Pin
Mr. Rogers2-Feb-06 5:18
Mr. Rogers2-Feb-06 5:18 
Question[C# & ASP.net] Control instances as null Pin
Distinctive1-Feb-06 12:19
Distinctive1-Feb-06 12:19 
This is part of a class libary that I am creating for a web site. I've created a class for a HtmlGenericControl that I want to use on my pages. It creates a box object that I can format easily (via the use of built in methods) and use on my ASP.net web site.

I've created the class, and it all compiles correctly, I can set it's properties and access it's methods, but when I create an instance of the class and try to add the control to the page I get a "null object" error.

Here's my code for the object:
	/// <summary><br />
	/// Creates a customisable content box for use on the page<br />
	/// </summary><br />
	public class ContentBox : HtmlGenericControl<br />
	{<br />
		// The top container of the box<br />
		HtmlGenericControl BoxTop;<br />
		// The header "h2" tag<br />
		HtmlGenericControl BoxHeader;<br />
		// The bottom container of the box<br />
		HtmlGenericControl BoxBottom;<br />
<br />
<br />
		/// <summary><br />
		/// Gets or sets the header text in the box<br />
		/// </summary><br />
		public string BoxHeaderText;<br />
<br />
		/// <summary><br />
		/// Control collection for the inner content of this box<br />
		/// </summary><br />
		public HtmlGenericControl BoxContent;<br />
<br />
<br />
		// Css class of the box<br />
		string BoxStyle;<br />
		/// <summary><br />
		/// Change the box type to wide content box<br />
		/// </summary><br />
		public void SetToContentWide() { BoxStyle = "box-wide"; }<br />
		/// <summary><br />
		/// Change the box type to left side content box<br />
		/// </summary><br />
		public void SetToContentLeft() { BoxStyle = "box-left"; }<br />
		/// <summary><br />
		/// Change the box type to right side content box<br />
		/// </summary><br />
		public void SetToContentRight() { BoxStyle = "box-right"; }<br />
		/// <summary><br />
		/// Change the box type to a sidebar box<br />
		/// </summary><br />
		public void SetToContentRightSidebar() { BoxStyle = "box"; }<br />
<br />
<br />
		// Box header css class<br />
		string BoxHeaderStyle;<br />
		/// <summary><br />
		/// Changes the header to dark green to stand out<br />
		/// </summary><br />
		public void SetHeaderImportant() { BoxHeaderStyle = "header"; }<br />
		/// <summary><br />
		/// Changes the header to dark green to stand out<br />
		/// </summary><br />
		public void SetHeaderNotImportant() { BoxHeaderStyle = "top"; }<br />
<br />
<br />
		/// <summary><br />
		/// Initialise the box<br />
		/// </summary><br />
		public ContentBox()<br />
		{<br />
			// Set default values<br />
			BoxStyle = "box-wide";<br />
			BoxHeaderStyle = "header";<br />
			BoxHeaderText = "";<br />
<br />
			// Set up this box<br />
			this.TagName = "div";<br />
			this.Attributes["class"] = BoxStyle;<br />
<br />
			// Create the box top<br />
			BoxTop = new HtmlGenericControl("div");<br />
			BoxTop.Attributes["class"] = BoxHeaderStyle;<br />
			this.Controls.Add(BoxTop);<br />
<br />
			// Header for the box<br />
			BoxHeader = new HtmlGenericControl("h2");<br />
			BoxHeader.InnerText = BoxHeaderText;<br />
			BoxTop.Controls.Add(BoxHeader);<br />
<br />
			// Create the bottom of the box<br />
			BoxBottom = new HtmlGenericControl("div");<br />
			BoxContent = new HtmlGenericControl("div");<br />
			this.Controls.Add(BoxBottom);<br />
		}

When I add the box to the page I simply use:
ContentBox _thebox = new ContentBox();
I can create an instance of the class, I can access it's methods, I can set it's properties, but when I try and use it on the page I get a null object error.

I think that the problem is that although when I create an instance of the class "ContentBox" it isn't being created as a new HtmlControl, but rather a null object.

Can anybody tell me how I get the object itself to become a new HtmlGenericControl when I create an instance of it?

Thanks
AnswerRe: [C# & ASP.net] Control instances as null Pin
Distinctive2-Feb-06 0:18
Distinctive2-Feb-06 0:18 
QuestionVS 2005 C# Class Wizard - it is gone? Pin
LuluSailor1-Feb-06 11:58
LuluSailor1-Feb-06 11:58 
AnswerRe: VS 2005 C# Class Wizard - it is gone? Pin
James Gupta1-Feb-06 21:01
professionalJames Gupta1-Feb-06 21:01 
QuestionSQLDMO for Oracle Pin
sam3151-Feb-06 11:42
sam3151-Feb-06 11:42 
QuestionUsing delegates with remoting in .net 2.0 Pin
Oyvind Hansen1-Feb-06 11:22
Oyvind Hansen1-Feb-06 11:22 
QuestionRemove a Child Entry from AD Pin
osamahmirza1-Feb-06 10:54
osamahmirza1-Feb-06 10:54 
QuestionControlling the focus Pin
3Dizard1-Feb-06 9:27
3Dizard1-Feb-06 9:27 
Questiontabcontrol glitchy Pin
jasonmog1-Feb-06 9:26
jasonmog1-Feb-06 9:26 
AnswerRe: tabcontrol glitchy Pin
Mark Greenwood1-Feb-06 13:47
Mark Greenwood1-Feb-06 13:47 
GeneralRe: tabcontrol glitchy Pin
jasonmog2-Feb-06 2:48
jasonmog2-Feb-06 2:48 
QuestionAproximate string matching Pin
Elvio Fernandez1-Feb-06 9:14
Elvio Fernandez1-Feb-06 9:14 
AnswerRe: Aproximate string matching Pin
Ingo1-Feb-06 21:39
Ingo1-Feb-06 21:39 
GeneralRe: Aproximate string matching Pin
Elvio Fernandez2-Feb-06 17:52
Elvio Fernandez2-Feb-06 17:52 
Question Additional C# 2005 Code Snippets From Microsoft Pin
Kevin McFarlane1-Feb-06 8:46
Kevin McFarlane1-Feb-06 8:46 
QuestionCrystal Viewer 9 RDC Pin
Bedevian1-Feb-06 8:33
Bedevian1-Feb-06 8:33 
QuestionSaving and viewing XML Files Pin
StevieGowland1-Feb-06 8:24
StevieGowland1-Feb-06 8:24 
AnswerRe: Saving and viewing XML Files Pin
malharone1-Feb-06 11:23
malharone1-Feb-06 11:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.