I have web application in this am using user control to place it in the table according to row depend on count.In user control there are 4 text boxes i have placed each usercontrol within table row and given unique id to this row at page load.Problem is,when i submit form i am trying to get the data by row id but control return null.i am getting row but within that row i am not able to find control. please have look in my code if i have done any worng.
MasterPage ctl00 = FindControl("ctl00") as MasterPage;
ContentPlaceHolder cplacehld = ctl00.FindControl("ContentPlaceHolder1") as ContentPlaceHolder;
foreach (SeatBookDetails sff in SBD)
{
TableRow trow = (TableRow)cplacehld.FindControl("Row_" + sff.SeatRowId.ToString() + "_" + sff.SeatRowno.ToString());
if (trow != null)
{
string ss = trow.ID;
TextBox txtcust = (TextBox)trow.FindControl("txtcustname");
if (txtcust != null)
{
}
TextBox txtprofession = (TextBox)trow.FindControl("txtprofession");
if (txtprofession != null)
{
}
}
}
When i inspect element i found structure i am attaching image of this have look.
What could be done here? How could i get this controls?
first provide properties in you user control class having only get accessors
like:
public string CustomerName { get { return txtCustName.Text; } }then you can loop through the rows and cells of the table using
foreachloopand then find you user control using:
if (_control is Usercontrol){
Usercontrol _form = (Usercontrol )_control;
string name = _form.CustomerName;
}
also make sure to load the usercontrol collections dynamically
Page_initorPage_Loadto have it accessible.