470,568 Members | 1,578 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,568 developers. It's quick & easy.

Controls.Add clash with Inner.Html?

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).EmployeeTyp e = "NR";

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

Any ideas?
Nov 19 '05 #1
1 2068
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)empN ominator));
content.Controls.Add(HRDiv);

---
www.societopia.net
"Frank_00001" wrote:
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).EmployeeTyp e = "NR";

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

Any ideas?

Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Guadala Harry | last post: by
1 post views Thread by E. Tom Jorgenson | last post: by
4 posts views Thread by Michael | last post: by
2 posts views Thread by Deepa K | last post: by
11 posts views Thread by Nick Gilbert | last post: by
16 posts views Thread by =?iso-8859-2?Q?K=F8i=B9tof_=AEelechovski?= | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.