Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET - How to write some html in the page? With Response.Write?

Tags:

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

like image 990
Magnetic_dud Avatar asked Jun 09 '09 11:06

Magnetic_dud


People also ask

What is the simplest way to write an HTML string to the output of an asp net page?

The ASP Write() method is used to display a string as an output on the webpage. It is a predefined method of the Response and Textstream type object. Parameter Values: This method contains the value i.e variant which represents the specified string that you want to display as an Output.

How can I write HTML code in cs file in asp net?

Content = "text/html; charset=utf-8"; head. Controls. Add(contentType); HtmlGenericControl title = new HtmlGenericControl("title"); title. InnerText = "Untitled Document"; head.

Can HTML code be used in ASP pages?

If you are already familiar with client-side scripting, you are aware that the HTML <SCRIPT> tag is used to enclose script commands and expressions. You can also use the <SCRIPT> tag for server-side scripting, whenever you need to define procedures in multiple languages within an . asp file.


2 Answers

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> 
like image 134
mmx Avatar answered Oct 21 '22 08:10

mmx


why don't you give LiteralControl a try?

 myLitCtrl.Text="<h2><p>Notify:</p> Alert</h2>"; 
like image 23
TheVillageIdiot Avatar answered Oct 21 '22 07:10

TheVillageIdiot