G
Guest
Scenario: I'm trying to create, based on a value from a drop-down list (1-100), a dynamic table row that contains a text box using the following code
//get the number from the combo bo
intNumWings = Convert.ToInt16(cboNumWings.SelectedValue)
//create a new table ro
HtmlTableRow rowText = new HtmlTableRow()
for (Int16 i = 1; i <= intNumWings; i++) {//begin creating wing text boxe
//create blank table element
HtmlTableRow rowWing = new HtmlTableRow()
HtmlTableCell celLabel = new HtmlTableCell()
HtmlTableCell celText = new HtmlTableCell()
TextBox txtWing = new TextBox ()
//set element propertie
celLabel.InnerHtml= "<b>Wing " + i + "<b>"
celLabel.Attributes.Add("width", "92")
txtWing.ID= "txtWing_" + Convert.ToString(i)
txtWing.Width= Unit.Pixel(283)
//add text box to table cel
celText.Controls.Add(txtWing)
//add cells to ro
rowWing.Cells.Add(celLabel)
rowWing.Cells.Add(celText)
//add row to tabl
tblWingSetup.Rows.Add(rowWing)
}//end wing text boxe
//add row to tabl
tblWingSetup.Rows.Add(rowText)
Problem: Every time I try to get the information from the text box using the FindControl method I keep receiving "Object reference not set to an instance of an object" error using the following code
TextBox myText = new TextBox ()
myText = (TextBox)FindControl ("_ctl0_txtWing_1");
Response.Write(myText.ClientID)
*I had to use the '_ctl0_' prefix, because when I opened the resulting HTML page I noticed this prefix. Now, I also receive the same message without the prefix too
Any help would be greatly appreciated
Jim
//get the number from the combo bo
intNumWings = Convert.ToInt16(cboNumWings.SelectedValue)
//create a new table ro
HtmlTableRow rowText = new HtmlTableRow()
for (Int16 i = 1; i <= intNumWings; i++) {//begin creating wing text boxe
//create blank table element
HtmlTableRow rowWing = new HtmlTableRow()
HtmlTableCell celLabel = new HtmlTableCell()
HtmlTableCell celText = new HtmlTableCell()
TextBox txtWing = new TextBox ()
//set element propertie
celLabel.InnerHtml= "<b>Wing " + i + "<b>"
celLabel.Attributes.Add("width", "92")
txtWing.ID= "txtWing_" + Convert.ToString(i)
txtWing.Width= Unit.Pixel(283)
//add text box to table cel
celText.Controls.Add(txtWing)
//add cells to ro
rowWing.Cells.Add(celLabel)
rowWing.Cells.Add(celText)
//add row to tabl
tblWingSetup.Rows.Add(rowWing)
}//end wing text boxe
//add row to tabl
tblWingSetup.Rows.Add(rowText)
Problem: Every time I try to get the information from the text box using the FindControl method I keep receiving "Object reference not set to an instance of an object" error using the following code
TextBox myText = new TextBox ()
myText = (TextBox)FindControl ("_ctl0_txtWing_1");
Response.Write(myText.ClientID)
*I had to use the '_ctl0_' prefix, because when I opened the resulting HTML page I noticed this prefix. Now, I also receive the same message without the prefix too
Any help would be greatly appreciated
Jim