Search code examples
c#asp.netweb-applicationsfindcontrol

FindControl with dynamic controls


I want to find dynamic controls. Example: - In my aspx:

<table id='vertragstypPVN_<%# Eval("Vertragstyp") %>' style="display: none" runat="server">

Table Ids will be generated like: vertragstypPVN_Test1, vertragstypPVN_Test2, etc.

  • In my aspx.cs, I want to find which table id is currenty using, but the method FindControl(string id) requires a static string id, I don't know how to deal with dynamic one. Any idea?. Many thanks

Solution

  • Since you generate the dynamic tables yourself, you already have a list of all the names that you have used. Use the Forms Collection to loop through all the tables and do a compare to hit to the right table.