Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 1111 Creating HTML Programatically

2 2222 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.

3 333 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

4 New Web Site 4

5 5 New Empty Web Site

6 6 Add New Item

7 7 Default.aspx

8 888 Boilerplate Created by Visual Studio

9 999 Customize the Boilerplate Set the title to a meaningful name: Date Time Demo Add a top level heading inside the tags: Creating HTML Programatically

10 10 Customized Boilerplate

11 11 Try it! Title Heading

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.

13 13 Invoking Server Code = says to insert the text produced by the code into the HTML, replacing the.

14 14 Server Code Output in Chrome View source on the browser.

15 15 What the Browser Received

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.

17 17 Server Code Shown Directly

18 18 The Design View Server code output is not shown at design time.

19 19 Page in Chrome

20 20 A Code Behind Function Note: This is not an event handler.

21 21 Invoking Code Behind Function

22 22 Page in Chrome

23 23 Page_Load What would happen if we did the Response.Write in the Page_Load event handler?

24 24 HTML Output from Page_Load

25 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( ). 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


Download ppt "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."

Similar presentations


Ads by Google