C#/ASP: FindControl null - is there a way to identify control ID's?
TL;DR
Is there any way to output a list of the actual ID's of dynamically created controls on a page, via the C# code? I want to see what it's seeing at runtime of the AJAX postback, because I'm aware that it's probably not seeing the ClientID (GridView1_Box-NormSeng_E-AfdID-1_0), but what I expect to be the UniqueID and ID doesn't seem to work either.
Background:
I'm having an issue with some code in which I generate ~1200 controls on a page, namely that FindControl always returns null when I try to access any of them.
I give these an ID composed of "Box" + row data name + "AfdID" + column ID:
txtBox.ID = "Box-NormSeng_E-AfdID-" + row_S3["Afd_C"];
When I look at the HTML render, the final ClientID of the first box is "GridView1_Box-NormSeng_E-AfdID-1_0".
However, whether I use regular postback to the same page, another page or AJAX, I'm just not able to locate that control in any context using FindControl.
Currently, for debugging, I'm looking for it in the specific cell it should be in:
foreach (GridViewRow row in GridView1.Rows) { TextBox contentBox = (TextBox)row.Cells[1].FindControl("GridView1_Box-NormSeng_E-AfdID-1"); ... }
I've tried searching for any combination of the different ID's: "GridView1_Box-NormSeng_E-AfdID-1_0", "GridView1_Box-NormSeng_E-AfdID-1", "Box-NormSeng_E-AfdID-1_0", "Box-NormSeng_E-AfdID-1", "GridView1$Box-NormSeng_E-AfdID-1_0" etc., but I always just get null.
I've tried looking in the context of master, page, gridview, rows, cells, form.
PS: The only reason all this is even necessary is because it's a table with static rows and dynamic columns, instead of the regular way around.
Edit: It should be noted that I'm very much a novice at ASP.NET and most especially AJAX - last time I did any real webdev was PHP in 2003. So I'm really hoping it's just a simple little thing I don't know or haven't considered :)
0 comments:
Post a Comment