![Page 1: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/1.jpg)
1111
Creating HTML Programatically
![Page 2: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/2.jpg)
2 2 2 2
Objectives
You will be able to Invoke C# code on the server from an ASP.NET
page. Write C# code to create HTML output for an
ASP.NET page dynamically.
![Page 3: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/3.jpg)
3 3 3
Example We will use C# code to output the current
date and time each time a page is requested by a browser. Later we will extend the example to show
dynamically created controls.
Start up Visual Studio and create a new C# ASP.NET empty web site. Date_Time_Demo
![Page 4: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/4.jpg)
New Web Site
4
![Page 5: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/5.jpg)
5
New Empty Web Site
![Page 6: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/6.jpg)
6
Add New Item
![Page 7: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/7.jpg)
7
Default.aspx
![Page 8: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/8.jpg)
8 8 8
Boilerplate Created by Visual Studio
![Page 9: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/9.jpg)
9 9 9
Customize the Boilerplate
Set the title to a meaningful name:Date Time Demo
Add a top level heading inside the <div> tags:
<h1>Creating HTML Programatically</h1>
![Page 10: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/10.jpg)
10 10 10
Customized Boilerplate
![Page 11: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/11.jpg)
11 11 11
Try it!
Title
Heading
![Page 12: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/12.jpg)
12 12 12
Server Code
We can add tags to the ASP.NET source to be processed on the server as the ASP markup is translated into pure HTML.
<% ... %>
Between the <% %> tags include normal C# code.
Typically function calls
Output goes into the HTML stream at that point. We saw an example last week where we put the
application start time onto a page as plain text.
![Page 13: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/13.jpg)
13 13 13
Invoking Server Code
= says to insert the text produced by the code into the HTML, replacing the <% %>.
![Page 14: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/14.jpg)
14 14 14
Server Code Output in Chrome
View source on the browser.
![Page 15: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/15.jpg)
15
What the Browser Received
![Page 16: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/16.jpg)
16 16 16
Response.Write()
The = inside <% %> is shorthand for Response.Write( );
Response is an object that embodies the response that will be sent back to the browser in response to the current request.
Its Write() method inserts text into the HTML output at the current position.
![Page 17: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/17.jpg)
17 17 17
Server Code Shown Directly
![Page 18: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/18.jpg)
18 18 18
The Design View
Server code output is not shown at design time.
![Page 19: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/19.jpg)
19
Page in Chrome
![Page 20: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/20.jpg)
20
A Code Behind Function
Note: This is not an event handler.
![Page 21: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/21.jpg)
21
Invoking Code Behind Function
![Page 22: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/22.jpg)
22
Page in Chrome
![Page 23: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/23.jpg)
23
Page_Load What would happen if we did the Response.Write
in the Page_Load event handler?
![Page 24: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/24.jpg)
24
HTML Output from Page_Load
![Page 25: 1111 Creating HTML Programatically. 2222 Objectives You will be able to Invoke C# code on the server from an ASP.NET page. Write C# code to create HTML](https://reader035.vdocuments.us/reader035/viewer/2022081517/5a4d1b697f8b9ab0599b2552/html5/thumbnails/25.jpg)
25
Summary We can invoke a function in the code behind file
from any place in a .aspx file to output any HTML using Response.Write( ).
<% Some_Function(); %> The HTML can be determined at run time from
user inputs, database contents, etc. The dynamically created HTML goes into the
page at the point where we invoke the Response.Write( ) function.
End of Presentation