Hi All,
I have created dynamic textboxes in a panel and trying to save them into database as a XML file, but I am receiving an error like
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControl'
Here is my piece of code which I have written
StringBuilder _StrResult = new StringBuilder();
_StrResult.Append("");
foreach (TextBox txt in pnlInterview.Controls)
{
foreach (Label lbl in pnlInterview.Controls)
{
Label lblLevel = (Label)pnlInterview.FindControl("lbl");
TextBox txtInterviewRound = (TextBox)pnlInterview.FindControl("txt");
_StrResult.Append("");
_StrResult.Append("" + lblLevel.Text.ToString() + " ");
_StrResult.Append("" + txtInterviewRound.Text.ToString() + " ");
_StrResult.Append("");
}
}
_StrResult.Append("");
return _StrResult;
Unable to recognize where it went wrong
I am unable to access oftype()
at starting foreach loop only I am receiving this error
any help is appreciated

Abubakar Dandoti91 reputationPosted Mar 4, 2016, 11:55 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 5, 2016, 12:14 AM EST
Ravi PatelRank #439 · 5.7K reputationPosted Mar 5, 2016, 12:39 AM EST
Abubakar Dandoti91 reputationPosted Mar 5, 2016, 12:40 AM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 5, 2016, 1:13 AM EST
Abubakar Dandoti91 reputationPosted Mar 6, 2016, 6:42 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 6, 2016, 7:11 PM EST
Abubakar Dandoti91 reputationPosted Mar 8, 2016, 8:05 PM EST
Phani KumarRank #2,870 · 500 reputationPosted Mar 8, 2016, 8:44 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts