Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

IDs again BIT MORE

  Asked By: Sam    Date: Sep 06    Category: Asp.net    Views: 751
  

I finished (ish) aying we should have a naming convention o fthe sorts "assembly.namespace.class.index " - but this isn't enough.

what we need to do is keep a cout of instances of a control.

How ??

Ok, if we dynamically create a control in code we can give it an id.

MyControl myc = new MyControl();
myc.ID = "whatever" + i (if we are in a loop)

But what if we need to access the child controls with that control ??? How do we give the child controls Id's ???

As explained myc.FindControl("achild") is no good since as soon as you create 2 MyControls you duplicate the "achild" id inside the control.
myc.FindControl("achild") DOES NOT restrict it to finding children called "achild" within myc .... it finds anything, anywhere called "achild" and will invariable chuck out an error @@Duplicate ID's@@

So we need to keep track of instances and generate id's of children based on those instances, and we cannot specify the id of the child within the control because it gets duplicated with every instance, which means we cannot access them using myc,FindControl("achild").

Really we should find the control and then name the child based on i in the loop above, but we cant get to the child without knowing its id.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Djoser Massri     Answered On: Sep 06

All code  I have mentioned refers NOT to System.Web.UI.UserControl but to System.Web.UI.WebControls.WebControl

My code using the UserControl works fine, but I want to wrap it up be able to put it in the VS toolbox.

The only worthy difference is that with the UserControl I LoadControl(ascx) file, which I have simply omitted with the webcontrols version.

Omitting it may be cocking things up regards to instances  and not being able to get to child  controls and so forth, the act of Loading a control  gives it substance, and perhaps "more than an instance" is created .... that much more so that it's children are specific to it's FindControl method (if you can catch my drift there). I know, I'm guessing.

I have tried to give  the webcontrols ID's and use Page.LoadControl("ID") but same problem in @@duplicate  id's@@ errors.

How would I load a webcontrol ???? Should I load a webcontrol ??

If you think about it, when you load a UserControl you are NOT using IT's ID are you, what exactly are you using ??? It's path ... which we haven't got in this case.

 
Didn't find what you were looking for? Find more on IDs again BIT MORE Or get search suggestion and latest updates.




Tagged: