0

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
Ragnarsson
  • 1,715
  • 7
  • 41
  • 74

2 Answers2

0

You must add runat="server" to your control and fix UniqueId of your control in order to find control

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • Hi, thanks. But in my case, I generate many tables with dynamic Ids, I can't fix uniqueId, that's my problem. Or do I get you right from your answer? – Ragnarsson Aug 23 '12 at 09:52
  • Hi i'am happy to help you must just add runat="server" if you want find your control in your code behind, if you don't add runat="sefver", you can't post your control, FindControl("Id") is server side method – Aghilas Yakoub Aug 23 '12 at 09:53
  • Hi, yeah, I've already added runat="server", I got your idea, but still at the server side, I don't know how to pass a dynamic control to FindControl(string id) method. for the record, I don't know the exact id of tables when they are generated. – Ragnarsson Aug 23 '12 at 10:02
0

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.

Sam
  • 30
  • 4