Asp.net slide5

54 201 0
Asp.net slide5

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Asp.net slide

Session 9Application, Server and Session Objects Exploring ASP.NET / Session 9 / 2 of 54ReviewTo make HTML elements programmatically accessible, it is necessary to indicate that an HTML element be parsed and treated as a server control. This can be done by adding a runat="server" attribute to the HTML element.The process of checking whether the user has filled up a form in the right format, and has not left any fields blank, is called validation.The validation controls available are as follows:RequiredFieldValidator: Helps in ensuring that a value is entered for a fieldCompareValidator: Checks if the value of a control is similar to the value of another controlRangeValidator: Checks if the value entered in a control is in the specified range of valuesRegularExpressionValidator: Checks if the value entered fits the regular expression that is specified CustomValidator: The value entered is checked by a client-side or server-side function written by the programmerValidationSummary: A list of all the validation errors occurring in all the controls is created, and can be displayed on the page. Exploring ASP.NET / Session 9 / 3 of 54Review Contd…The Page object has a property called IsValid, that returns true if all the validation tests are successful, and vice-versa.To disable client-side validation, the ClientTarget property can be set to downlevel.Code Behind is a feature that enables the developer to write the code to provide the required functionality in a separate file than that of the code to create the graphics for the web page Exploring ASP.NET / Session 9 / 4 of 54ObjectivesDiscuss the Global.asax fileExplain the events in the Global.asax fileUse the Application ObjectUse the Server ObjectUse the Session Object Exploring ASP.NET / Session 9 / 5 of 54Global.asax FileStored in Root Directory of applicationDefines boundary of applicationInitialises application or session level variables Connects to databases Sends cookies Exploring ASP.NET / Session 9 / 6 of 54Events in Global.asaxEvents DescriptionApplication_Start Fired when the first ASP.NET page in the current application directory (or its sub-directories) is called.Application_EndFired when the last session of the application ends. Also fired when the web application is stopped, using the Internet Services Manger snap-in. Application_BeginRequestFired every time a page request begins (ideally when a page is loaded or refreshed). Exploring ASP.NET / Session 9 / 7 of 54Events in Global.asax Contd…Events DescriptionApplication_EndRequestFired every time a page request ends (that is every time the page executes on the browser) Session_Start Fired every time a new session begins. Session_End Fired when the session ends. For the various ways in which a session can end, refer to the session on the Session object. Exploring ASP.NET / Session 9 / 8 of 54Global.asax ExampleGlobal.asax<script language="C#" runat="server"> protected void Application_Start(Object sender, EventArgs e){} protected void Session_Start(Object sender, EventArgs e){Response.Write( "Session Started <br>");} Exploring ASP.NET / Session 9 / 9 of 54Global.asax Example protected void Application_BeginRequest(Object sender, EventArgs e){ Response.Write("<h1>Application Begins</h1>"); Response.Write ("Application request begins <br>");} protected void Application_EndRequest(Object sender, EventArgs e){ Response.Write ("Application request ends <br>");} Exploring ASP.NET / Session 9 / 10 of 54Global.asax Example protected void Session_End(Object sender, EventArgs e){Response.Write("Session ended");} protected void Application_End (Object sender, EventArgs e){}</script> [...]... Response.Write ("Page Load event "); } Exploring ASP.NET / Session 9 / 11 of 54 Test Global.asax Output Exploring ASP.NET / Session 9 / 12 of 54 Application Object Represents an instance of an ASP.NET application Object[varName] Application Level Session Level Application ["greeting"] = "Welcome to our sites"; Exploring ASP.NET / Session 9 / 13 of 54 Application Object Example 1 void... ["sessioncount"]); } Exploring ASP.NET / Session 9 / 16 of 54 Application Object Output Output Initially Output after refreshing Output after reopening the browser Exploring ASP.NET / Session 9 / 17 of 54 Controlling Access  Application variables can be accessed and updated by all the pages of an ASP.NET application  Since the variable retains the currently assigned... Exploring ASP.NET / Session 9 / 23 of 54 Execute Method Output Exploring ASP.NET / Session 9 / 24 of 54 Transfer Method The Transfer() method is used to transfer the execution completely to the specified page Unlike the Execute() method, the control is lost from the calling page when this method is executed Syntax: Server.Transfer (“Array.aspx"); Exploring ASP.NET / Session 9 / 25 of... Exploring ASP.NET / Session 9 / 34 of 54 MapPath Output Exploring ASP.NET / Session 9 / 35 of 54 MapPath Example 2 MapPath-ServerVariables void Page_Load(Object Src, EventArgs e) { Response.Write (Server.MapPath (Request.ServerVariables.Get ("PATH_INFO"))); } Exploring ASP.NET. .. "Salesman"; job[3]= "Manager"; Application ["j"] = job; Exploring ASP.NET / Session 9 / 20 of 54 Array.aspx void Page_Load(Object Src, EventArgs E) { int i = 0; String[] k; k = (String[])Application["j"]; for (i = 0; i . }</script></html> Exploring ASP. NET / Session 9 / 12 of 54Test Global.asax Output Exploring ASP. NET / Session 9 / 13 of 54Application Object Represents an instance of an ASP. NET. cookies Exploring ASP. NET / Session 9 / 6 of 54Events in Global.asaxEvents DescriptionApplication_Start Fired when the first ASP. NET page in the

Ngày đăng: 15/11/2012, 14:44

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan