Server-SideScriptingwithASP.Net_第1頁
Server-SideScriptingwithASP.Net_第2頁
Server-SideScriptingwithASP.Net_第3頁
Server-SideScriptingwithASP.Net_第4頁
Server-SideScriptingwithASP.Net_第5頁
已閱讀5頁,還剩45頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Server-Side Scripting with ASP.NetISYS 5461Dynamic Page Client-Side Script ExampleDemo: TimeNowClient.HtmNew Page 1The time is now document.write time()iHour=hour(time()if iHour 12 thendocument.write good morningelsedocument.write good afternoonend if2Problems with Client-Side ScriptSource code reve

2、aledCompatibility problemMozillaIE3Dynamic Web Pages Server-Side Script ExampleDemo: TimeNow.aspxThe time is now The time is now %dim iHouriHour=Now.Hour()if iHour 12 thenresponse.write(good morning)elseresponse.write (good afternoon)end if%Note: Need web server; cannot open by Page.Work for both Mo

3、zilla and IE.4Client-Side vs Server-Side ScriptingClient-side scripting:The browser requests a page.The server sends the page to the browser.The browser sends the page to the script engine.The script engine executes the script.Server-side scripting:The browser requests a page.The server sends the pa

4、ge to the script engine.The script engine executes the script to produce page.The server sends the page to the browser.The browser renders the page.Demo: ShowSum.htm, Web Form5Webpage EditorFrontPage demoVisual Studio .NetWeb Forms tabHTML tab6HTML IntroductionHeading section, , , , etc.Body section

5、, , to , , Formatting: , , , Comment: List ImageTable: , : a new row in table, : a new cell in a table row.Form: , , , 7META TagThe meta tag allows you to provide additional information about the page that is not visible in the browser:Redirection:“3” is number of seconds.Demo using FrontPage8TABLE

6、Tag 9FORM TagForm attribute:Action: Specify the URL of a program on a server or an email address to which a forms data will be submitted.Method: Get: the forms data is appended to the URL specified by the Action attribute as a QueryString.Post: A prefered method for database processing. Forms data i

7、s sent separately from the URL. Name: Forms nameDemo: TestFormGet.Htm, TestFormPost.Htm10QueryStringA QueryString is a set of name=value pairs appended to a target URL.It can be used to pass information from one webpage to another.To create a QueryString:Add a question mark (?) immediately after a U

8、RL.Followed by name=value pairs separated by ampersands (&).Example: 11Creating a QueryStringEntered with a URL:As part of a URL specified in an anchor tag.Via a form sent to the server with the GET method.Created by script12SCRIPT TagClient-side script:Server-side script:statements13HTML Tags and E

9、ventsLink : click, mouseOver, mouseOutImage : abort(loading is interrupted), error, load.Area : mouseOver, mouseOutBody : blur, error, focus, load, unloadFrameset: blur, error, focus, load, unloadFrame: blur, focusForm: submit, resetTextbox, Text area: blur, focus, change, selectButton, Radio button

10、, check box: clickList: blur, focus, change14Event HandlerEvent handler name: on + event nameEx. onClickThree ways of writing handler:1. Within the tag2. Event function: onCLick=“clickHandler()”15ASP.NETASP.NET is a server-side technology for creating dynamic web pages.ASP.NET allows you to use a se

11、lection of full programming languages. The default language is VB .NET. ASP.NET files have a .aspx extension.16ASP.NET in the .NET Framework1. The client requests a web page.2. The web server locates the page.3. If the page is an ASP.NET page, it is sent to the Common Language Runtime for compilatio

12、n and execution.4. The HTML produced by the CLR is returned to the browser.17Benefits of Server-Side TechnologyBrowser compatibility: Every browser reads HTML.Protection of source code.Controls are server-side objects with properties, methods and events.Separating code from content. Embedded codeCod

13、eBehind18Elements of an ASP.Net PageDirectivesCode blocksASP.NET controlsHTML tags and text.Server-side include directives19DirectivesA directive controls how an ASP.Net page is compiled.Page directives: Specify default language, enable tracing and debugging for a page., Imports name spacesTo proces

14、s Access database, we need to import:20Inserting ASP.NET Code into Web PagesPlace ASP.NET code between and with a RUNAT attribute.Your script- ASPNET/ADD2.ASPXsub clickHandler(Sender As Object, E As EventArgs)sum.text=cstr(cdbl(num1.text)+cdbl(num2.text)end subInline Code Block: ASP code is placed b

15、etween .The time is now The time is now “=“ is shorthand for response.writeServer-side comments:Alternative place to store code: CodeBehind21Server-Side IncludeTo include a an page:Demo: timeNow.aspx22ASP.NET Object ModelClientServerRequest ObjectResponse ObjectServer ObjectSessionObjectApplicationO

16、bject23ASP.NET Request ObjectWhen a page is requested, much information is passed along with the request, such as the URL, queryString, and data from a form. The request object allows you to get the information passed along with the request.It is created from the System.Web.HttpRequest class.Demo: t

17、estRequest.Htm, TestRequest.aspx24%response.write ( cid= & request.form(cid) & )response.write ( cname= & request.form(cname)& ) Response.Write( & Request. & ) Response.Write( httpMethod & Request.HttpMethod & ) Response.Write( path & Request.Path & ) Response.Write( Url & Request.Url.ToString & ) R

18、esponse.Write( urlReferer & Request.UrlReferrer.ToString & ) Response.Write( HostName & Request.UserHostName & ) Response.Write( HostAddress & Request.UserHostAddress & )%25Request Object CollectionsQueryStringcid = Request.queryString(“CustID”)cName=Request.queryString(“CustName”)FormA form with tw

19、o text boxes:CustID, CustNamecid = Request.Form(“CustID”)cName=Request.Form(“CustName”)CookiesClientCertificatesPath, ApplicationPath, PhysicalApplicationPath, etc.Demo: testReqForm.htm, testReqForm.aspx26TestReqForm EnterCID: EnterName: checkbox1 checkbox 2 radio1 radio 2 A B C listbox 27TestReqFor

20、m.Aspx%response.write ( cid= & request.form(cid) & )response.write ( cname= & request.form(cname)& )response.write ( hidden variable= & request.form(hidden1)& )if request.form(C1)=ON thenresponse.write (You select checkbox 1)end ifif request.form(C2)=ON thenresponse.write (You select checkbox 2)end

21、ifif request.form(R1)=V1 thenresponse.write (You select Radio 1)elseresponse.write (You select Radio 2)end ifresponse.write ( listBox= & request.form(D1)& )response.write ( & request.queryString(myquery)& )%28ASP.NET Response ObjectThis object allows you to send information back to client.It is crea

22、ted from the System.Web.HttpResponse class.Properties:BufferCookies (a collection)Methods:Response.Write (“.”) * MessageBox is not available for web project *.Response.Clear(), Response.Flush(): clear/flush bufferResponse.Redirect (“URL”)29BufferWhen ASP.Net is running the code, it gradually builds

23、up the HTML that will be sent back to the browser. As the HTML is generated, it is placed in a buffer. Normally, the HTML is held in the buffer so that it isnt sent to the browser until the page finishes executing. Response.Buffer: The default value for this property is true which means the page is

24、buffered and sent in one block.Response.Buffer=Falsesends html as it is generated.30The Application and Session Objects Application state: A central, site-wide store of variables that we can get from any page.A session is a single visit to a web site, and normally includes visits to a number of page

25、s. Each time a visitor comes to your web site, a session object is created for the visitor. Session state is a store of variables that relates to a session.31Examples of Using the Application and Session ObjectsExamples of session variables are: users id, users name, Shopping cart, etc. Examples of

26、application variables are: visitor counter.32Working with the Application and SessionTo place a value into the Application and Session simply assign it a key and then assign the value:Application (“Name”)=“Smith”Session (“Age”)=25To read values from the Application and Session:Cname=Application(“Nam

27、e”)myAge = Session(“Age”)To remove an item, or all items: Remove, RemoveAll()Application.Remove(“Name”)Session.RemoveAll()33ApplicationState/SessionState PropertiesApplicationState:Lock, UnlockSessionState:SessionIDTimeOut34The Events of the Application and Session ObjectsApplication_OnStartWeb site

28、 start, and the first viewApplication_OnEndWeb site shut downSession_OnStartSession_OnEnd35The Global.ASAX FileEvery ASP.NET application has this special script file.Must reside in the web sites root directory.It can contain script code that belongs to the application, or each session.The event hand

29、ler of the application and session objects must be placed in the Global.asax file.36Web Form vs HTML FormHTML Form: A web page that contains one or more HTML form controls such as textbox, checkbox, dropdown list, and button inside an HTML tag.Web Form: A web page that contains: ASP.NET server contr

30、ols, and/or HTML form controls inside a tag.ASP.NET code that produces dynamic content to be displayed within the web form.37Web Form EventsEvery time a page is called the page object goes through a series of stage: initializing, loading, processing and disposing of information. It happens every tim

31、e a round trip to the server occurs.Page_InitPage_Load: Occurs when a page is visible.Control EventsPage_UnloadNote: A webform is handled by itself.Demo: web form with regular HTML controls ASPNET/TestRequestFormHTML.ASPX38ASP.NET Server ControlsIntrinsic Controls: These controls correspond to their

32、 HTML counterparts. Ex. Textbox, listbox, button, etc.Data-Centric Controls: Controls used for binding and displaying data from a data source, such as the DataGrid control.Rich Controls: Such as Calendar, AdRotator.Validation Controls: Such as RequiredFieldValidator.Namespace:System.Web.UI.Webcontro

33、ls39Benefits of Using ASP.NET Intrinsic Server ControlsThey are programmable objects.Respond to eventsHave properties40The ControlAn alternative way of displaying text on a web page.Properties:IDBackColor, ForeColor, Height, WidthTextVisible41Other Intrinsic ControlsDemo: ASPNET/TestTextBox.aspxDemo

34、: TestDropdownlist.aspxListItem controlAppleOrangeBananaNote: Using VS.Net you may have to set AutoPostBack property to true to generate the ListItem tags automatically.Demo:TestListBox.aspx42CheckListBox ExampleDim i As ListItemFor Each i In CheckBoxList1.Items If i.Selected Then Response.Write(You select & i.Text) End IfNext43Server Control EventsObject BrowserSystem.Web.UI.Webcontrols44PostbackPostback is the process by which the b

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論