Unique ID's in custom web part and how to add properties by id

Evine Beursken asked on January 31, 2017 11:01

Based on the following Article I have a follow up question. (https://devnet.kentico.com/articles/custom-web-part-with-editable-regions---how-to-ensure-unique-ids-of-nested-editable-regions).

To ensure unique ID's of controls inside a web part, in the Page_init function the ID of the web part itself is added to the ID that might otherwise be not unique. However, how can you call the ID after updating it?

I have for example a custom web part that contains a asp:repeater control with ID="Repeater1".

In the OnInit function (I can not override a Page_Init function) I change this ID by adding the ID of the web part: Repeater1.ID = "Repeater1" + this.ID;

However, after this, I can not find the repeater by its other ID, only Repeater1 is found with intellisense.

Recent Answers


David te Kloese answered on January 31, 2017 14:51

Evine,

In the code of your custom web part it will always reference to the local repeater control as Repeater1. Since you probably named it that way. Why would you need this new ID? Are you needing it from within an other webpart or code?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.