ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio –...

20
ASP.NET Hands-On Lesson 03 By Susan L. Miertschin

Transcript of ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio –...

Page 1: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

ASP.NET Hands-OnLesson 03

By Susan L. Miertschin

Page 2: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Use a Text Editor?

Notepad – bare bones? Notepad – not really feasible with server-

side development in ASP.NET Visual Studio and its integrated

development environment that includes the SmartSense enabled text editor –much better – essential, really

Page 3: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Getting Started with Visual Studio – Our Development Environment Changes!

Open Visual StudioFile – New Project

Page 4: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Getting Started with Visual Studio – What Type of Project?

ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Page 5: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Add a Web Form to the Project

Name the new Web From Recommendations.aspx

Also – your project starts from Default.aspx – where the Deitel textbook project named that page Options.aspx

Page 6: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Deitel’s ASP.NET Exercise on Session Tracking – Edit Default. aspx

In Design view, create the interface shown in Figure 25.20 (a) and (b) – more or lessHere is my version of it

Page 7: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Deitel’s ASP.NET Exercise on Session Tracking – RuntimeDefault. aspx

Note that when the interface is running the label with the links is not visible – provided you used the settings as indicated in the Deitel text in Figure 25.20

Page 8: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Write Code in the Code-Behind File of Default.aspx (or Options.aspx)

In Solution Explorer, click the icon to See All Files in order to see the code-behind filesThe code you need to write is in Figure 25.21 of the Deitel textbook

Page 9: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Use the Visual Studio Integrated Development Environment (IDE)

You should not type the code for the event procedures directly from the bookUse the IDE instead

Page 10: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Use the Visual Studio Integrated Development Environment (IDE)

The IDE creates the code structure for the event procedure

Here you type the code for the Page_Init event

This code adds data to the books HashTable

The HashTable will be created on the Web Server when the user interacts with the web application

The data from the HashTable is accessed by the Web Server in order to know what information to put into the cookie it will send back to the client

Page 11: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Continue Writing Code

Write the code for the Page_Load event

Page_Load follows Page_Init in the sequence of events

The code is executed only if the Page_Load event is occurring due do a PostBack from the server

A PostBack occurs because the user has interacted in a way to cause the server to resend the page (see page 1041 in the text for a more complete discussion of the postback event)

So the If condition is false when the page loads initially

Page 12: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Write the Code to Create the Cookie

The cookie is sent to the user’s computer via the Response object

Page 13: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Run the Application

Page 14: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Keep Running – Trying Out Different Functionality

Page 15: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Finish Section 25.4

Complete the application as in continues on pages 1051 through 1062 in the Deitel textbook

Page 16: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Time to Publish?

Uploading the contents of your Web application to the Web server is called publishing

Save all and Build!!!!! DO NOT FORGET TO BUILD IMMEDIATELY PRIOR TO PUBLISH !!!!!!

Choose Publish from the Build menu

Change the Publish Method to FPSE (Front Page Server Extensions)

Page 17: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

Publish Your Web App

A subweb named ASP.NET_HandsOn_03 has been created for you under your username web folder

Type the full url as the Target Location:

http://cot-cis2336-01.cougarnet.uh.edu/secnnnnn/username/ASP.NET_HandsOn_03

http://cot-cis2336-01.cougarnet.uh.edu/secnnnnn/username/ASP.NET_HandsOn_03

Page 18: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

See the Results (Hopefully You Won’t See Either of These)

Page 19: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

If You Do See an Error

It may be because you forgot to build prior to publish

Try the Save All –Build – Publish routine again

Then email me if the error persists

Page 20: ASP.NET HandsOn 03smiertsc/2336itec/ASP.NET_HandsOn_03.pdfGetting Started with Visual Studio – What Type of Project? ASP.NET Web Application Project – You may name it: ASP.NET_HandsOn_03

ASP.NET Hands-OnLesson 03

By Susan L. Miertschin