in Education by
I have a very simple operation where I try to add a HtmlGenericControl to another HtmlGenericControl : protected void Page_Load(object sender, EventArgs e) { HtmlGenericControl div = new HtmlGenericControl("div"); HtmlGenericControl p = new HtmlGenericControl("p"); div.Controls.Add(p);//exception occurs } An exception is thrown in the debugger only - the page itself renders as though nothing had happened. However something definitely does happen, as in a larger portion of code, controls are not being rendered as they should. The actual exception is: {InnerText = '((System.Web.UI.HtmlControls.HtmlContainerControl)(div)).InnerText' threw an exception of type 'System.Web.HttpException'} I can't understand why this is happening, as you should be able to add controls to each other in this manner. Note that from the first answer, I tried again with IDs but it still doesn't work: I have some more information. When using a Placeholder control as the parent, there is no exception: protected void Page_Init() { PlaceHolder ph = new PlaceHolder(); HtmlGenericControl p = new HtmlGenericControl("p"); ph.Controls.Add(p);//no problem } JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
"An exception is thrown in the debugger only - the page itself renders as though nothing had happened." That's fine in that InnerText won't work if there are child controls; that is by design because it doesn't want to render the whole hierarchy of controls at that time for various performance, lifecycle, and side affect reasons. "... something definitely does happen, as in a larger portion of code, controls are not being rendered as they should." What does that mean? What is rendering incorrectly in the "larger portion" of code? My guess is that is a problem somewhere else and not related to what you have in your question here. So I think you're fine. Ignore the exception in InnerText on the parent control. You need to ask a new Question regarding whatever issue you are having with the "larger portion" of your code.

Related questions

0 votes
    I have user control named DateTimeUC which has two textboxes on its markup: I am dynamically creating this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I have user control named DateTimeUC which has two textboxes on its markup: I am dynamically creating this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    I have user control named DateTimeUC which has two textboxes on its markup: I am dynamically creating this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 13, 2022 in Education by JackTerrance
0 votes
    Part of the series of controls I am working on obviously involves me lumping some of them together in to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I have an Entity (QuoteSheet) that contains a child entity (QuoteTask), which is loaded using the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 16, 2022 in Education by JackTerrance
0 votes
    Background: I have an old web CMS that stored content in XML files, one XML file per page. I am ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 10, 2022 in Education by JackTerrance
0 votes
    We create new sites in IIS 6 (Windows Server 2003) using IIS Manager. When these sites are created ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 27, 2022 in Education by JackTerrance
0 votes
    We have created a web application, using ASP.NET, that allows users to upload documents and attach them to ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 16, 2022 in Education by JackTerrance
0 votes
    I know this appears subjective and is likely to be closed but I'll ask anyway. When you use a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I know this appears subjective and is likely to be closed but I'll ask anyway. When you use a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    I am refactoring some CSS on a website. I have been working on, and noticed the absence of traditional ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    When I use Build->Publish Web Site in Visual Studio 2008, most of the time it compiles the site, ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    Here's the scenario: After installing the ASP.NET application (using install shield) in IIS6, when I right ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 18, 2022 in Education by JackTerrance
0 votes
    Here's the scenario: After installing the ASP.NET application (using install shield) in IIS6, when I right ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 17, 2022 in Education by JackTerrance
...