2

I'm adding controls to a panel on an Asp.Net webforms page and I'd like to change the html it generates. A simplified example of what I'm doing:

Dim control1 As New HiddenField()
control1.ID = "Control1"
control1.Value = "Text"

Dim control2 As New HiddenField()
control2.ID = "Control2"
control2.Value = "Text"

Panel1.Controls.Add(control1)
Panel1.Controls.Add(control2)

This generates the following HTML:

<input type="hidden" name="Control1" id="Control1" value="Text" /><input type="hidden" name="Control2" id="Control2" value="Text" />

Is there a way to ensure that there's a newline in between every control? The current source is a pretty big mess when you add more controls. I'd like the html to be formatted like this:

<input type="hidden" name="Control1" id="Control1" value="Text" />
<input type="hidden" name="Control2" id="Control2" value="Text" />
2
  • Are you sure it should be Panel2.Controls.Add(control2)? Looks like it should be Panel1.Controls.Add(control2) Commented May 31, 2012 at 9:31
  • You're right, edited the example Commented May 31, 2012 at 9:50

2 Answers 2

2

Assuming both controls should be added to Panel1, try this...

Panel1.Controls.Add(control1)
Panel1.Controls.Add(New LiteralControl(Environment.NewLine))
Panel1.Controls.Add(control2)
Sign up to request clarification or add additional context in comments.

Comments

0

If you don't like how certain control generates itself, you can always create one yourself. This is a fairly simple example and I'm sure you'd have it done it few minutes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.