473,378 Members | 1,417 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,378 software developers and data experts.

Accessing Child Controls

Hi,
I have an object which inherits from WebControl (CUSTOM : WebControl)

In this object I have code in which I add child contols:
protected override void CreateChildControls()
{
//this.Controls.Clear();
CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil();
DataTable objDT = objCustomFieldUtil.GetDataTable("custom");
for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Trim() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToString();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.Add(new LiteralControl("<tr><td class=\"regLabelCell\"
width=\"20%\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));
}
....etc.
}
I'm having problems accessing those controls that I add there from another
function. When I do the following code intCount returns 0!

foreach (Control ctrl in this.Controls)
{
this.intCount++;
}

AHHH! what happend to the reference?

Thanks

-Jon
Nov 17 '05 #1
5 1688
Sometimes kids are like that. Especially if you were too liberal in raising
them.
Nov 17 '05 #2
Actually I didn't define the structrue of the LBL's etc. I'm generating
based on someone else class.

-Jon

"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
You'll notice that those labels I add through create child controls are
inherit from controls themselves. LBL myLbl = new LBL(); LBL inherits from Label

so myLbl has a couple properties and methods

Ok, here's what I'm trying to do and having trouble with.
From within CUSTOM : WebControl, INamingContainer

I want to create another function like editable in which I would access
those dynamically created LBL's and mess with thier properties
(functionality to make it editable or not is already encapulated, I just
need to set a bool to true or false)

Whey I try to access these it seems they are Literal controls or somthing.

Thanks for the help, if you can even understand me :)

-J

"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
I'm not clear where your for loop is exactly.
Is this happening outside of the control?
If so, you should try changing your code to this:

foreach (Control ctrl in myCustomControl.Controls)
{
this.intCount++;
}

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire

"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Hi,
I have an object which inherits from WebControl (CUSTOM : WebControl)
In this object I have code in which I add child contols:
protected override void CreateChildControls()
{
//this.Controls.Clear();
CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil();
DataTable objDT = objCustomFieldUtil.GetDataTable("custom");
for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Trim() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToString();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.Add(new LiteralControl("<tr><td class=\"regLabelCell\"
width=\"20%\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));
}
...etc.
}
I'm having problems accessing those controls that I add there from another function. When I do the following code intCount returns 0!

foreach (Control ctrl in this.Controls)
{
this.intCount++;
}

AHHH! what happend to the reference?

Thanks

-Jon



Nov 17 '05 #3
Should I be adding each of those LBL's I create into an array or collection
for future access?

-Jon
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
I'm not clear where your for loop is exactly.
Is this happening outside of the control?
If so, you should try changing your code to this:

foreach (Control ctrl in myCustomControl.Controls)
{
this.intCount++;
}

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire

"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Hi,
I have an object which inherits from WebControl (CUSTOM : WebControl)
In this object I have code in which I add child contols:
protected override void CreateChildControls()
{
//this.Controls.Clear();
CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil();
DataTable objDT = objCustomFieldUtil.GetDataTable("custom");
for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Trim() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToString();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.Add(new LiteralControl("<tr><td class=\"regLabelCell\"
width=\"20%\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));
}
...etc.
}
I'm having problems accessing those controls that I add there from another function. When I do the following code intCount returns 0!

foreach (Control ctrl in this.Controls)
{
this.intCount++;
}

AHHH! what happend to the reference?

Thanks

-Jon


Nov 17 '05 #4
That sounds like a good thing to try.

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire
"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Should I be adding each of those LBL's I create into an array or collection for future access?

-Jon
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
I'm not clear where your for loop is exactly.
Is this happening outside of the control?
If so, you should try changing your code to this:

foreach (Control ctrl in myCustomControl.Controls)
{
this.intCount++;
}

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire

"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Hi,
I have an object which inherits from WebControl (CUSTOM : WebControl)
In this object I have code in which I add child contols:
protected override void CreateChildControls()
{
//this.Controls.Clear();
CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil();
DataTable objDT = objCustomFieldUtil.GetDataTable("custom");
for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Trim() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToString();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.Add(new LiteralControl("<tr><td class=\"regLabelCell\"
width=\"20%\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));
}
...etc.
}
I'm having problems accessing those controls that I add there from another function. When I do the following code intCount returns 0!

foreach (Control ctrl in this.Controls)
{
this.intCount++;
}

AHHH! what happend to the reference?

Thanks

-Jon



Nov 17 '05 #5
This whole thread is me talking to myself LOL ;-)

So what I did was renamed the protected override void CreateChildControls()
to private void myCreateChildControls() and everything started working like
I wanted it to. That is the method calls to the LBL's etc.

I guess I just don't understand the purpose of the protected override void
CreateChildControls() and was using it incorrectly.
"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Should I be adding each of those LBL's I create into an array or collection for future access?

-Jon
"Steve C. Orr, MCSD" <St***@Orr.net> wrote in message
news:eP**************@TK2MSFTNGP10.phx.gbl...
I'm not clear where your for loop is exactly.
Is this happening outside of the control?
If so, you should try changing your code to this:

foreach (Control ctrl in myCustomControl.Controls)
{
this.intCount++;
}

--
I hope this helps,
Steve C. Orr, MCSD
http://Steve.Orr.net
Developer for Hire

"Jonathan Williams" <an**@covad.net> wrote in message
news:bh**********@sun-news.laserlink.net...
Hi,
I have an object which inherits from WebControl (CUSTOM : WebControl)
In this object I have code in which I add child contols:
protected override void CreateChildControls()
{
//this.Controls.Clear();
CustomFieldUtil objCustomFieldUtil = new CustomFieldUtil();
DataTable objDT = objCustomFieldUtil.GetDataTable("custom");
for(intCount = 0; intCount < objDT.Rows.Count; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Trim() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToString();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.Add(new LiteralControl("<tr><td class=\"regLabelCell\"
width=\"20%\">"));
this.Controls.Add(myLbl);
this.Controls.Add(new LiteralControl("</td>"));
}
...etc.
}
I'm having problems accessing those controls that I add there from another function. When I do the following code intCount returns 0!

foreach (Control ctrl in this.Controls)
{
this.intCount++;
}

AHHH! what happend to the reference?

Thanks

-Jon



Nov 17 '05 #6

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

Similar topics

6
by: Chris Styles | last post by:
Dear All, I've been using some code to verify form data quite happily, but i've recently changed the way my form is structured, and I can't get it to work now. Originally : The form is...
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
4
by: John Holmes | last post by:
I'm using data to rename some web controls on a form that uses a repeater contol and so it can have mulitple instances of the same control set. The controls get renamed (thanks to Steven Cheng's...
6
by: arvee | last post by:
Is there a way to access controls (and their properties) in a user control? The Web Form Designer marks controls as 'Protected' which makes them inaccessable from the host form. If I mark them as...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
0
by: Mac via DotNetMonster.com | last post by:
Hi all, Is there a way for the MDI parent to reference controls on the active MDI child form? What I actually want to achieve is to know what control on the MDI child currently has focus. Is...
4
by: raj_genius | last post by:
I hav two queries, whc are as follows: FIRSTLY: is it possible to access the controls(by name) of a parent form(MDI) from its child forms??if yes then how??plzz provide a coded example in VB if...
9
by: JohnR | last post by:
I have the name of a control in a string variable and I want to change one of the controls properties. Right now I recursively scan all the controls on the form until I get one whose name matches...
3
by: =?Utf-8?B?dmJ0cnlpbmc=?= | last post by:
Background: I have a windows form called 'frmMain'. On this form, I have a LABEL control called 'lblWorkStatus', and it's property is set to PUBLIC. On another form, I have a process that checks...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.