creating web app

29
Create a Web App Hans-Petter Halvorsen, M.Sc. Step by step Exercises ASP.NET Web forms

Upload: doanngoc

Post on 02-Jan-2017

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Creating Web App

CreateaWebApp

Hans-PetterHalvorsen,M.Sc.

StepbystepExercises

ASP.NETWebforms

Page 2: Creating Web App

WebAppExercise• VisualStudio• C#• ASP.NETWebForms• ASP:ActiveServerPages

LotsofresourcesforWebDevelopment:http://www.w3schools.comRecommended!!!

Page 3: Creating Web App

WebServer

ASP.NETC#/VB.NET

.NETFramework

WebBrowser

HTML JavaScriptServer-side

Client

ASP.NET

CSS

Theserver-sideASP.NETpagesareconvertedontheservertoHTMLpagesbeforeitissenttotheclient

ASP.NETisusedtocreatedynamicwebpages

Page 4: Creating Web App

WebSites

ASP.NETC#/VB.NET

.NETFramework

ASP.NETWebPages

ASP.NETWebForms

ASP.NETMVC

ASP.NET– DifferentwaysofcreatingWebSiteswithASP.NET

http://www.asp.net

Youcanuse(atleast)3differentapproacheswhencreatingWebSiteswithASP.NET

Page 5: Creating Web App

5

ASP.NETWebPages

ASP.NETWebForms

ASP.NETMVC

• SimiliartothedesktopdevelopmentmodelusedinWPF• GUI(*.aspxfiles)andCode(*.aspx.cs)isseparated

• MVC– Model- View– Controller• Anewdevelopmentmodelwhereyousplityourdevelopment

into3parts/components:ModelsforData,ViewsforDisplayandControllersforInput

• SingePageModel(Theserver-sidecodeismixedinbetweentheHTML)

• UsestheRazorsyntax(.cshtmlfiles)• SimiliarasClassicASPandPHP• AtoolcalledMicrosoftWebMatrixisoptimizedforthis

developmentmodel,butyoucanalsouseVisualStudioifyouwantto.

Page 6: Creating Web App

ASP.NETASP.NETsupportsthreedifferentdevelopmentmodels:

VerysimilartoPHPGUIandCodemixedtogetherIfyouarefamiliarwithPHPthisisagoodstartingpoint.

TheWebversionofclassicWinFormsGUIandCodeisseparated.IfyouarefamiliarwithWinFormsorWPF,thisisagoodchoice

FormoreexperiencedWebDevelopers

Page 7: Creating Web App

ASP.NET

http://www.asp.net/get-started/websites

Page 8: Creating Web App

Exercise:WebForm

Hans-PetterHalvorsen,M.Sc.

Page 9: Creating Web App

ASP.NETWebFormExample

9

Whenyouarefinished, yourWebAppshould looksomething likethis:

WhenyouenteryourNameintheTextBoxandclicktheOKButton,theprogramshould respondwithagreetings.

Page 10: Creating Web App

ASP.NETWebFormExample

10http://www.asp.net Remembertoselect“AddtoSourceControl”

Page 11: Creating Web App

CreateNewSolution

11

Youhavelotsofchoiceshere– butwejustwanttocreateaverysimpleWebFormApp

Page 12: Creating Web App

CreateNewWebForm

12

Page 13: Creating Web App

WinForm1.aspxPage

“HTML”CodeEditor

WYSIWYGHTMLDesigner

YoucaneitherwritetextintheCodeEditororintheDesignerwindow

UsedtocreatetheGUI/HMI

Page 14: Creating Web App

HelloWorldExample- GUI

14

Page 15: Creating Web App

HelloWorldExample– TheCode

15

WebForm1.aspx.cs

Page 16: Creating Web App

RunningtheApplication

16

EnteryourNameandclickOKbutton

Note!RemembertoCheck-inyour filesintoTFS

Page 17: Creating Web App

Exercise:WebFormwithDatabaseCommunication

Hans-PetterHalvorsen,M.Sc.

Page 18: Creating Web App

DatabaseExerciseqCreateaDatabasecalledLIBRARYandaBOOKtableinSQLServer

qEntersomeTestdataintotheBOOKtable

18

Page 19: Creating Web App

DatabaseExerciseqFilla“GridView”withdatafromtheDatabaseTable(BOOK),asshownbelow

Page 20: Creating Web App

20

Usethe“Wizard”inordertocreateallthe“magic”youneedinyourapplication

Page 21: Creating Web App

21

Whenfinishingthe“Wizard”,your.aspxpageshouldlooksomethinglikethis

Page 22: Creating Web App

22

Asyousee- NoCodeneededtobewritteninthisexampleJ

ThisisOKforquickdemos– butforprofessionalapplications,youneedtousesomehardcoreADO.NETorsimiliarframeworks.

Page 23: Creating Web App

Exercise:WebFormwithDatabaseCommunication

fromScratchHans-PetterHalvorsen,M.Sc.

Page 24: Creating Web App

DatabaseExercise2qThistime:CreateeverythingfromscratchusingC#codeandADO.NET.

qFilla“DropDownList”withBookNamesfromtheDatabase

qPrinttheAuthorNamebasedontheselectedBookNameonthescreen

Beginning ASP.NET4.5inC#,Apress,2012,MatthewMacDonald(SafariBooksOnline)

Page 25: Creating Web App

Your.aspxpageshouldlooksomethinglikethis:

Page 26: Creating Web App

ThecodecouldbeimprovedbycreatingaseparateClasswhereyoucreatethisMethod

Page 27: Creating Web App

EventHandler

ThecodecouldbeimprovedbycreatingaseparateClasswhereyouputthiscodeintoaMethod

ThiscodeisexecutedwhentheWebPageisloaded

Page 28: Creating Web App

Web.config

AllkindogconfigurationshouldbestoredintheWeb.configfile,includingDatabaseConnectionStrings,etc.

Page 29: Creating Web App

Hans-PetterHalvorsen,M.Sc.

UniversityCollegeofSoutheastNorwaywww.usn.no

E-mail:[email protected]:http://home.hit.no/~hansha/