473,503 Members | 1,650 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

protected override void CreateChildControls()

Jon
Hi!
I'm creating a custom Server Control which implements the method in the
subject line (Protected override void CreateChildControls)

In here I have the following code:

LBL myLbl = new LBL();
myLbl.ID = "MyLbl";
myLbl.Text = objCustomFieldUtil.GetName("custom");
this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));

Now what I'd like to do is add the child controls dynamically by looping
through a Data Table:

for(int i = 0; i < objDT.Rows.Count; i++)
{
//Implement Adding Controls here
}

The problem arises that I need to declare my label or textbox before I can
added it. Anyone know a way around this?

Thank you.



Nov 17 '05 #1
4 2446
Jon, it's not a problem:

for(into I = 0; I < bond.Rows.Count; I++)
{
Label aspLabel = new Label();
aspLabel.ID = "Label" + I.ToString();
aspLabel.Text = bond.Rows[i]["field"];
this.Controls.Add(aspLabel);
}

Of course, you want to do this in the right place, and maybe you want to
enclose each label in a "<td></td>".
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

P.S. Did you do this.Controls.Clear() at the beginning of
CreateChildControls?

"Jon" <an**@covad.net> wrote in message
news:bg**********@sun-news.laserlink.net...
Hi!
I'm creating a custom Server Control which implements the method in the subject line (Protected override void CreateChildControls)

In here I have the following code:

LBL myLbl = new LBL();
myLbl.ID = "MyLbl";
myLbl.Text = objCustomFieldUtil.GetName("custom");
this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));

Now what I'd like to do is add the child controls dynamically by looping
through a Data Table:

for(int i = 0; i < objDT.Rows.Count; i++)
{
//Implement Adding Controls here
}

The problem arises that I need to declare my label or textbox before I can
added it. Anyone know a way around this?

Thank you.


Nov 17 '05 #2
Jon
John,
Thanks...Sorry for not trying that first (makes me look like a
dumba$$ In my defense it was late and I was on the way out :-) )

I did not do this.Controls.Clear(), what does that do exactly...remove all
references to child controls on the postback?

Thanks,

Jon

"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
Jon, it's not a problem:

for(into I = 0; I < bond.Rows.Count; I++)
{
Label aspLabel = new Label();
aspLabel.ID = "Label" + I.ToString();
aspLabel.Text = bond.Rows[i]["field"];
this.Controls.Add(aspLabel);
}

Of course, you want to do this in the right place, and maybe you want to
enclose each label in a "<td></td>".
--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

P.S. Did you do this.Controls.Clear() at the beginning of
CreateChildControls?

"Jon" <an**@covad.net> wrote in message
news:bg**********@sun-news.laserlink.net...
Hi!
I'm creating a custom Server Control which implements the method in

the
subject line (Protected override void CreateChildControls)

In here I have the following code:

LBL myLbl = new LBL();
myLbl.ID = "MyLbl";
myLbl.Text = objCustomFieldUtil.GetName("custom");
this.Controls.Add(new LiteralControl("<td class=\"regLabelCell\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));

Now what I'd like to do is add the child controls dynamically by looping
through a Data Table:

for(int i = 0; i < objDT.Rows.Count; i++)
{
//Implement Adding Controls here
}

The problem arises that I need to declare my label or textbox before I can added it. Anyone know a way around this?

Thank you.



Nov 17 '05 #3
"Jon" <an**@covad.net> wrote in message
news:bg**********@sun-news.laserlink.net...
John,
Thanks...Sorry for not trying that first (makes me look like a
dumba$$ In my defense it was late and I was on the way out :-) )

I did not do this.Controls.Clear(), what does that do exactly...remove all
references to child controls on the postback?


Controls.Clear() removes all of your child controls. You do it at the
beginning of CreateChildControls to ensure that the set of child controls is
exaclty the set created in CreateChildControls.

Now, I never quite tracked it down, but I've had problems with
CreateChildControls being called twice. Calling Controls.Clear solved the
problem.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com

Nov 17 '05 #4
Cool, thanks for the tip and all the help.

-Jon
"John Saunders" <jo***********@surfcontrol.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
"Jon" <an**@covad.net> wrote in message
news:bg**********@sun-news.laserlink.net...
John,
Thanks...Sorry for not trying that first (makes me look like a
dumba$$ In my defense it was late and I was on the way out :-) )

I did not do this.Controls.Clear(), what does that do exactly...remove all references to child controls on the postback?
Controls.Clear() removes all of your child controls. You do it at the
beginning of CreateChildControls to ensure that the set of child controls

is exaclty the set created in CreateChildControls.

Now, I never quite tracked it down, but I've had problems with
CreateChildControls being called twice. Calling Controls.Clear solved the
problem.

--
John Saunders
Internet Engineer
jo***********@surfcontrol.com


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6461
by: Dan Cimpoiesu | last post by:
Hello What does mean when a protected modifier is apllied to a class. I want to inherit a protected class defined in another class, I saw that the microsoft programmers achieved that. But I...
4
7330
by: p988 | last post by:
using System; using System.Windows.Forms; using System.Drawing; class MyForm : Form { MyForm () { Text = "Windows Forms Demo"; }
7
7246
by: TT (Tom Tempelaere) | last post by:
Hi there The line marked *** doesn't compile. I wonder why the designers of C# decided to disallow this. Rationale? Are there plans to change this? This feature forces me to make things public...
8
11783
by: Keith Smith | last post by:
Could some one help me a little? I am trying to understand when/where you would ever want to use "protected override..." code such as this. How is this any different from creating a...
3
40282
by: gordon | last post by:
can someone please explain what protected override void is ? what is it used for? thanks Doug
0
1157
by: milmus tender | last post by:
Hi, we have some customized EditorParts, which inherits from a DefaultEditor. This DefaultEditorPart inherits from the standard EditorPart-Class. In this DefaultEditorPart we override the...
5
1886
by: =?Utf-8?B?V0o=?= | last post by:
If I have a class A that has a virtual public function DoSomething() Class A { public: virtual void DoSomething(); } then I override this function to protected is class B Class B: public...
6
2472
by: REH | last post by:
Can someone please tell me what is wrong with this snippet of code? GCC is telling me that "foo2 is protected within this context" (that I cannot use it with BBB). class AAA { protected:...
7
3626
by: =?Utf-8?B?cmFtbzk5NDE=?= | last post by:
Hi, Is there any way disable using "protected override void OnPaint(..." method out of the assembly. I create usercontrol and i do not want user adds extra codes OnPaint method for securtity...
0
7201
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7083
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
7328
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...
1
6988
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7456
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5578
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,...
0
4672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3166
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.