Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Accessing Child Controls

Reply
Thread Tools

Accessing Child Controls

 
 
Jonathan Williams
Guest
Posts: n/a
 
      08-14-2003
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


 
Reply With Quote
 
 
 
 
Guenther Liebowitz
Guest
Posts: n/a
 
      08-14-2003
Sometimes kids are like that. Especially if you were too liberal in raising
them.


 
Reply With Quote
 
 
 
 
Jonathan Williams
Guest
Posts: n/a
 
      08-14-2003
Actually I didn't define the structrue of the LBL's etc. I'm generating
based on someone else class.

-Jon

"Jonathan Williams" <(E-Mail Removed)> wrote in message
news:bhgq69$4o5$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:bhejss$qqh$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Jonathan Williams
Guest
Posts: n/a
 
      08-14-2003
Should I be adding each of those LBL's I create into an array or collection
for future access?

-Jon


"Steve C. Orr, MCSD" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:bhejss$qqh$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Steve C. Orr, MCSD
Guest
Posts: n/a
 
      08-14-2003
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" <(E-Mail Removed)> wrote in message
news:bhh1gj$dju$(E-Mail Removed)...
> Should I be adding each of those LBL's I create into an array or

collection
> for future access?
>
> -Jon
>
>
> "Steve C. Orr, MCSD" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:bhejss$qqh$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Jonathan Williams
Guest
Posts: n/a
 
      08-15-2003
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" <(E-Mail Removed)> wrote in message
news:bhh1gj$dju$(E-Mail Removed)...
> Should I be adding each of those LBL's I create into an array or

collection
> for future access?
>
> -Jon
>
>
> "Steve C. Orr, MCSD" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:bhejss$qqh$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP! Child controls of child controls not visible to web app lisa@starways.net ASP .Net Building Controls 0 05-05-2005 09:14 PM
Mixing child properties and child controls - how? Donal McWeeney ASP .Net Web Controls 3 02-14-2005 02:51 AM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
Accessing Properties of Custom Controls child Controls Moldy ASP .Net Building Controls 8 09-05-2003 03:39 PM
Accessing Properties of Custom Controls child Controls Moldy ASP .Net Web Controls 8 09-05-2003 03:39 PM



Advertisments