Controls.Add clash with Inner.Html?

G

Guest

I'm trying to dynamically create controls on a <DIV>; however I want to add
an <HR> in between certain controls, seems simple enough. I'm having trouble
with the <HR>, I was going to just add it using InnerHtml.Insert; but for
some reason after adding a control, the InnerHtml seems to get corupted,
<error: an exception of type: {System.Web.HttpException} occurred>.

Here's basically what I want to do, content is the <DIV> and the control I'm
adding is a user control.

Control empNominator = null;
empNominator = LoadControl("EmployeeRecordReadOnly.ascx");
if (empNominator != null)
{
((EmployeeRecordReadOnly)empNominator).EmployeeType = "NR";

((EmployeeRecordReadOnly)empNominator).UpdateEmployeeControlsFromData(DataSet1);
content.Controls.Add(((EmployeeRecordReadOnly)empNominator));
content.InnerHtml.Insert(content.InnerHtml.Length, "<HR style=\"HEIGHT:
1px\" width=\"100%\" SIZE=\"1\">");
}

Any ideas?
 
G

Guest

The InnerHtml property brings the literal content of the GenericControl but
in your code below "content" had only a control "empNominator" that had not
been rendered to HTML yet. Try creating a generic control for the <HR>
markup then add it to your content control:

HtmlGenericControl HRDiv = new HtmlGenericControl ();
HRDiv.InnerHtml ="<HR style=\"HEIGHT: 1px\" width=\"100%\" SIZE=\"1\">";

content.Controls.Add(((EmployeeRecordReadOnly)empNominator));
content.Controls.Add(HRDiv);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top