tags:

views:

161

answers:

2

I want to 'echo' a string separated by delimeters like: sergio|tapia|1999|10am

the Body of an HTML page.

How can I achieve this? Thank you!

+6  A: 

Use Response.Write(string).

There are a couple of shortcuts to Response.Write if you are trying to output on the page:

<%="sergio|tapia|1999|10am"%>

Or

<%:"sergio|tapia|1999|10am"%> (.NET 4.0)

See here for the different options.

Oded
For example say I response.write() twice. Are the both string output in separate lines? Or are they in a single html tag?
Serg
@Sergio Tapia - Depends where you output each one. Can't really tell you without seeing some code.
Oded
Sergio, just try it. However, to create multiple lines you would need to add a `"\n"` at the end, and to make things show up on separate lines, consider using `<br/>`.
Hamish Grubijan
@Sergio Using `Response.Write` twice will place the second string right after the first with no line break. `Response.Write("Hello")` followed by `Response.Write("World")` will output "HelloWorld".
Paperjam
+1  A: 

You can use Response.Write(str) both in code-behind and on the .ASPX page:

<%
Response.Write(str)
%>

Using Response.Write() in code-behind places the string before the HTML of the page, so it's not always useful.

You can also create a server control somewhere on your ASPX page, such as a label or literal, and set the text or value of that control in code-behind:

.ASPX:

<asp:Label id="lblText" runat="server" />

Code-behind:

lblText.Text = "Hello world"

Outputs in HTML:

<span id="lblText">Hello World</span>

If you don't want <span>s added, use a literal:

<asp:Literal id="litText" runat="server" />

And set the value attribute of the literal instead of the text attribute:

litText.Value = "Hello World"
Paperjam