views:

227

answers:

1

Hi, I am creating huge amounts of dynamic controls, and for everything that must have an ID assigned, I assign it using a guaranteed unique variable(unless 64bits overflows from just controls).

Now, I have a problem though. I have a duplicate control somewhere and I can not discover where it is added or anything because it doesn't happen until after Page_Load, which means, it is out of my own code when an exception is thrown(I think at like Render or some other internal function).

The control name is "ctlXXX" where XXX is a number(right now, always 244) this control ID is not being made by me. It is being made by ASP.Net automatically(as none of my IDs are prefixed with ctl). So how do I correct this error that I can not see? Can anyone suggest ways of finding my error(I really hope this isn't a bug in ASP.Net)?

Also, I got the error just recently by using a Copy function which will do a Memberwise copy on a custom control, and then it will reset any controls to have either a unique ID or to be null as this part happens before controls are loaded into the custom control, which is a descendant of Panel)

Can anyone give me advice on how to find this bug?

+1  A: 

I think you want to look at the INamingContainer interface. I think it will solve your problem but you will have to derive a new control class to do it.

csharptest.net
Ok, that helps some. Now I'm actually getting an error about my own controls being duplicated(which still shouldn't happen) so I'll have to dig around a little more..
Earlz
hmm.. well now I'm getting controls not found.. so I'll have to figure out how to convert my code to use this while allowing some names to exist between controls...
Earlz
You'll need to change calls to FindControl() to be calledon the parent instance of INamingContainer. In other words call FindControl to find the container, then again to find the control.
csharptest.net