I have a four column table with a variable amount of rows, which needs to support selection of single or multiple rows. I have decided to use CheckBoxes in one of the columns to implement this functionality but I cannot find a way of reading the state of the controls after they have been generated.
First off, I started using JQuery to slip the CheckBoxes straight into the table on the client side, assuming I could just use "FindControl()" to look it up when the form was posted. FindControl failed miserably even after adapting it to search all controls on the page recursively.
After some googling it appeared that ASP.Net simply doesn't allow or function as I had hoped and tried so instead I changed the code to add all the CheckBoxes to a Table in the code file and there was no difference.
As I am much more familiar with using the C# HttpListener, I attempted to read back the posted form data and process it myself, only to find that ASP uses some form of either encryption or obfuscation on the data rendering it a more time consuming task that its worth to even look at that method.
There is almost no restriction to how I achieve this but I simply don't know enough about ASP.Net to work this out alone, especially after google has failed me!
If you need to see some code feel free to ask, but please be specific.
This is the code I have TRIED to use to find a control, its a right mess at the moment:
// I assign the name "CHK_SEL_" + i.ToString() to the ID, but that is on a page with a master page. Examining the ID with chrome shows that the ClientID is actually MainContent_CHK_SEL_i, so I search for that too.
Control c = MyFind(this, "CHK_SEL_2");
ControlCollection cc = this.Controls; // Everything except this line, results in null. and after examining this using visual studio, I cannot manually find the controls I am after either.
Control ccc = this.FindControl("CHK_SEL_2");
Control cccc = SearchControl(this, "CHK_SEL_2");
Control ccccc = MyFind(this, "MainContent_CHK_SEL_2");
Control cccccc = this.FindControl("MainContent_CHK_SEL_2");
Control ccccccc = SearchControl(this, "MainContent_CHK_SEL_2");
private Control MyFind(Control search, string ID)
{
int i = 0;
Control c = search.FindControl(ID);
if (c != null) return c;
while (search.Controls.Count > i && (c = MyFind(search.Controls[i++], ID)) == null) ;
return c;
}
public static Control SearchControl(Control controlToSearch, string controlID)
{
if (controlToSearch.ID == controlID) return controlToSearch;
for (int i = 0; i < controlToSearch.Controls.Count; i++)
{
Control c = SearchControl(controlToSearch.Controls[i], controlID);
if (c != null) return c;
}
return null;
}