473,834 Members | 1,913 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CreateChildCont rols()
{
//this.Controls.C lear();
CustomFieldUtil objCustomFieldU til = new CustomFieldUtil ();
DataTable objDT = objCustomFieldU til.GetDataTabl e("custom");
for(intCount = 0; intCount < objDT.Rows.Coun t; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Tri m() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToStri ng();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.A dd(new LiteralControl( "<tr><td class=\"regLabe lCell\"
width=\"20%\">" ));
this.Controls.A dd(myLbl);
this.Controls.A dd(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 1715
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, INamingContaine r

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.ne t> wrote in message
news:eP******** ******@TK2MSFTN GP10.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 CreateChildCont rols()
{
//this.Controls.C lear();
CustomFieldUtil objCustomFieldU til = new CustomFieldUtil ();
DataTable objDT = objCustomFieldU til.GetDataTabl e("custom");
for(intCount = 0; intCount < objDT.Rows.Coun t; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Tri m() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToStri ng();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.A dd(new LiteralControl( "<tr><td class=\"regLabe lCell\"
width=\"20%\">" ));
this.Controls.A dd(myLbl);
this.Controls.A dd(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.ne t> wrote in message
news:eP******** ******@TK2MSFTN GP10.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 CreateChildCont rols()
{
//this.Controls.C lear();
CustomFieldUtil objCustomFieldU til = new CustomFieldUtil ();
DataTable objDT = objCustomFieldU til.GetDataTabl e("custom");
for(intCount = 0; intCount < objDT.Rows.Coun t; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Tri m() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToStri ng();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.A dd(new LiteralControl( "<tr><td class=\"regLabe lCell\"
width=\"20%\">" ));
this.Controls.A dd(myLbl);
this.Controls.A dd(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.ne t> wrote in message
news:eP******** ******@TK2MSFTN GP10.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 CreateChildCont rols()
{
//this.Controls.C lear();
CustomFieldUtil objCustomFieldU til = new CustomFieldUtil ();
DataTable objDT = objCustomFieldU til.GetDataTabl e("custom");
for(intCount = 0; intCount < objDT.Rows.Coun t; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Tri m() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToStri ng();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.A dd(new LiteralControl( "<tr><td class=\"regLabe lCell\"
width=\"20%\">" ));
this.Controls.A dd(myLbl);
this.Controls.A dd(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 CreateChildCont rols()
to private void myCreateChildCo ntrols() 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
CreateChildCont rols() 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.ne t> wrote in message
news:eP******** ******@TK2MSFTN GP10.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 CreateChildCont rols()
{
//this.Controls.C lear();
CustomFieldUtil objCustomFieldU til = new CustomFieldUtil ();
DataTable objDT = objCustomFieldU til.GetDataTabl e("custom");
for(intCount = 0; intCount < objDT.Rows.Coun t; intCount++)
{
if (objDT.Rows[intCount]["Name"].ToString().Tri m() != "")
{
LBL myLbl = new LBL();
myLbl.ID = "Label" + intCount.ToStri ng();
myLbl.Text = objDT.Rows[intCount]["Name"].ToString();
this.Controls.A dd(new LiteralControl( "<tr><td class=\"regLabe lCell\"
width=\"20%\">" ));
this.Controls.A dd(myLbl);
this.Controls.A dd(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
2749
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 called "form1", and I have selects called "PORTA", "PORTB" ... etc...
8
4946
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, System.EventArgs e) { MessageBox.Show("keyboard button pressed!"); } Following is the code to load the frmTestBaby
4
2059
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 help) in a click event of the button that is pushed to enter data. Each time the button is clicked it sends the ID entered by the user to query the database and return information. The renamed controls then include the ID in the name of the...
6
2256
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 Public, I can access them, but the next time the controls are manipulated in the design mode, they are converted back to Protected. Is there an obvious/easy way around this? Thanks.
10
4032
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 application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
0
968
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 there also a way to have an event on the MDI parent that fires everytime the focus on a child form changes? regards,
4
3644
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 possible.. for example..i hav a menu in the parent form named "Administrator" whic has an item "mnuLogIn"..now when i click on login..another child form named "frmLogIn" is displayed..what i want to happen is this: when login form(frmLogIn) is...
9
1919
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 the name in my string variable, then I know I have the correct control and can proceed to change the property. However all that searching seems like overkill. Does anyone know of a way to directly access the control if it's name is in a string...
3
1820
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 on the status of a project that our company is working on. Programmatically, if the status changes, I want to relay that information to the 'lblWorkStatus' control on the main form. My code looks like this:
0
10795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10512
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10550
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7760
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5627
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5796
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3981
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3083
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.