tags:

views:

328

answers:

7

I need that some html in the area in the asp.net page that i am coding, is changed according to a string variable. I was thinking about creating a label, and then change the text on it.

But the string variable contains something like:

<h2><p>Notify:</p> alert</h2>

So, I don't feel that give this to a label text is a good idea

How i can do? Using response.write? If I use response.write, my added code will be at the beginning of the html source, how i can tell him to add it in a specific ?

Thank you

+2  A: 

If you really don't want to use any server controls, you should put the Response.Write in the place you want the string to be written:

<body>
<% Response.Write(stringVariable); %>
</body>

A shorthand for this syntax is:

<body>
<%= stringVariable %>
</body>
Mehrdad Afshari
+2  A: 

Use a literal control and write your html like this:

literal1.text = "<h2><p>Notify:</p> alert</h2>";
tekBlues
+2  A: 

You should really use the Literal ASP.NET control for that.

Philippe Leybaert
+3  A: 

why don't you give LiteralControl a try?

 myLitCtrl.Text="<h2><p>Notify:</p> Alert</h2>";
TheVillageIdiot
i didn't know about LiteralControl...sorry, i am a beginner.... :-$
Magnetic_dud
don't mind everyone was (beginner) sometime :)
TheVillageIdiot
+1  A: 

ASPX file:

<h2><p>Notify:</p> <asp:Literal runat="server" ID="ltNotify" /></h2>

ASPX.CS file:

ltNotify.Text = "Alert!";
roosteronacid
+1  A: 

You can go with the literal control of ASP.net or you can use panels or the purpose.

Meetu Choudhary
+1  A: 

If you want something lighter than a Label or other ASP.NET-specific server control you can just use a standard HTML DIV or SPAN and with runat="server", e.g.:

Markup:

<span runat="server" id="FooSpan"></span>

Code:

FooSpan.Text = "Foo";

Marc
cool! I didn't know that
Magnetic_dud
I can't see how "<span runat='server' />" is lighter than "<asp:Literal runat='server' />".
Mehrdad Afshari