I am getting the following error while i submit a form after i added a dropdown box in my designer
System.NullReferenceException: Object reference not set to an instance of an object. at WebApplication1._Default.collectEmailBodyText() in C:\v1.5_production_05June09\Default.aspx.vb:line 219
Below is the extra two lines that i added in collectEmailBodyText()
tempPanelDropDownBox = DirectCast(form1.FindControl(("txt_" & panelUsed & "_ddinput") + counter.ToString()), DropDownList)
tempCollector = tempCollector + “: ” + tempPanelDropDownBox.SelectedItem.Text
As the other posters have said, it seems likely that the call to the
FindControlmethod is returningNothing(null), so then trying to access a property likeSelectedItemwill cause theNullReferenceException.Your code
FindControl("txt_" & panelUsed & "_ddinput") + counter.ToString())is trying to find a drop-down list with a server ID of some strings concatenated together and then what looks like a variable number at the end. This seems a bit odd; do you really want the number at the end? I’d expect something like that when using dynamically-added controls.