views:

60

answers:

1

I am keeping track of all of the controls rendered on a form in a dictionary.....Its a very fast and convenient way to getting a rendered control reference given a specific key.....

Lets say I go ahead and delete a control which nestles in the middle of a series of 3 controls....

Before I delete the middle control the last control in the series has the clientID:

ctl13_xxxxx_ctl00_0_ctl02_0_ctl00_2_ctl02_xxxxxx

After deletion the middle control is removed, the form re-rendered and the clientId of the last control (which effectively takes the place of the middle control) is:

ctl13_xxxxx_ctl00_0_ctl02_0_ctl00_1_ctl02_xxxxxx

This is all well and good on the rendered form....However, I need to get at the updated clientID from within my code, and althouh I have a reference to the controls in the dictionary their clientIDs are not being updated...

It is almost as if that at the point I load the control the ClientId is only a snap shot of what it is when it is first rendered. Obviously on a postback after a delete, the full control hierarchy is being created, I am taking effectively taking snap shot of the controls, the delete is performed and then I am left with an out of date reference/copy of the control as it was only when it was initially rendered.

My only other alternative is to get at this client Id and renumber my record of it, which is a little onerous.

A: 

The clientIds are updated by the PreRender stage of the lifecycle (taking into account Init,Load, Validate, Event).

I was attempting to remove the control using the client Id (from the registry) , which is very messy. Also, at the point I inspect the control at PreRender its client Id is zeroed out (well in some fashion)

The point of the answer is as follows: If performing dynamic alterations to a form. The client Ids are not changed for controls until at least some point after Init but definitely by PreRender

I hope this helps someone, it is hugely insightful lol

brumScouse