Quote:
Object reference not set to an instance of an object.
Details about the error you see:
NullReferenceException Class (System) | Microsoft Docs[
^]
Quote:
A NullReferenceException exception is thrown when you try to access a member on a type whose value is null
Possibly because:
1. You've forgotten to instantiate a reference type
2. You've forgotten to dimension an array before initializing it.
3. You get a null return value from a method, and then call a method on the returned type.
4. You're using an expression (for example, you're chaining a list of methods or properties together) to retrieve a value
5. You're enumerating the elements of an array that contains reference types, and your attempt to process one of the elements throws
6. Exception is thrown by a method that is passed null
Quote:
getting error on FindControl
This means that the name of the control is incorrect or not present in that control hierarchy where you are trying to find it.
foreach (Control c in pnl.Controls)
{
TextBox temp_txt = (TextBox)pnl.FindControl(c.ID);
td.Controls.Add(temp_txt);
With above code, it's not clear on what you want to do actually. Above code is looping through all the controls present in the panel and then add them to a table and then in end add table back to panel. It's like controls are at two places. Then you have tr/td added to table per control in a loop. It's messed up - mostly this leads to mismatch of controls and error. Further, are all controls in panel a textbox that you cast into?