Documente Academic
Documente Profesional
Documente Cultură
NET
Objectives
Ver. 1.0
Slide 1 of 41
ASP.NET offers various AJAX server controls that implement AJAX functionality in a Web application. Some of the controls offered by ASP.NET are:
ScriptManager control ScriptManagerProxy control UpdatePanel control UpdateProgress control Timer control
Ver. 1.0
Slide 2 of 41
The ScriptManager control can be used to manage the client script for AJAX-enabled Web applications. The ScriptManager control provides:
The custom scripts The JavaScript classes The JavaScript proxy classes
The ScriptManager control can be added to a Web page by using the following code snippet:
<asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager>
Ver. 1.0
Slide 3 of 41
AsyncPostBackTimeout
EnablePageMethods
EnablePartialRendering
Ver. 1.0
Slide 4 of 41
The ScriptManager control has certain limitation, that is, you can add only one instance of the ScriptManager control to a Web page. A Web page can include the control either directly or indirectly inside a nested component such as a user control or a content page for a master page. This means that if a master page has a ScriptManager control, then you cannot add a ScriptManager control to the content page, which is using the master page. This limitation can be overcome by using the ScriptManagerProxy Control. The ScriptManagerProxy control enables you to add scripts and services that are specific to nested components.
Ver. 1.0
Slide 5 of 41
Services
Gets a ScriptReferenceCollection object that contains a ScriptReference object for each service that is explicitly registered with the ScriptManagerProxy control.
Ver. 1.0
Slide 6 of 41
The UpdatePanel server control is a container control that helps you create highly interactive and responsive Web applications. The UpdatePanel control is used with the ScriptManager control to enable partial-page rendering. The UpdatePanel control can contain other Web server controls such as, Label and TextBox controls. You can add an UpdatePanel controls to a Web page by using the following code snippet:
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> </asp:UpdatePanel>
Ver. 1.0
Slide 7 of 41
Triggers
UpdateMode RenderMode
Ver. 1.0
Slide 8 of 41
The UpdateProgress control is used to provide information on the status of the partial-page updates in the UpdatePanel controls. If the partial-page update is slow, you can use the UpdateProgress control to provide a message about the status of the update. The UpdateProgress control can be customized. You can modify the default content and the layout of the UpdateProgress control. The UpdateProgress control can be added to a Web page by using the following code snippet:
<asp:UpdateProgress ID="UpdateProgress1" runat="server"> </asp:UpdateProgress>
Ver. 1.0
Slide 9 of 41
DisplayAfter
DynamicLayout
Ver. 1.0
Slide 10 of 41
The Timer control is used with the UpdatePanel control to perform partial-page updates at a predefined time interval. The Timer control can also be used to post the entire Web page at a predefined time interval. You can use the Timer control in your Web application to perform the following tasks:
Periodical updates of one or more UpdatePanel controls without refreshing the entire Web page. Execution of the code at the server each time the Timer control causes a postback. Synchronous postback of the entire Web page to the Web server at predefined time intervals.
Ver. 1.0
Slide 11 of 41
The Timer control embeds a JavaScript component into the Web page. You can place multiple Timer controls in a Web page. You can associate each Timer control with a different UpdatePanel controls. You can add a Timer control to a Web page by using the following code snippet:
<asp:Timer ID="Timer1" runat="server> </asp:Timer>
Ver. 1.0
Slide 12 of 41
Interval
Ver. 1.0
Slide 13 of 41
Problem Statement:
The AlbumDetails.aspx Web page enables a user to select an album and get details about that album. As the number of records increase in the database, the processing of the Web page will take time and the user has to wait to get the details. In addition, the user cannot interact with the Web page till the details are retrieved from the server. To make the page interactive and enable users to interact with the Web page while the album details are retrieved, you have to implement AJAX. In addition, you have to use the UpdateProgress control to display the status while the album details are being retrieved from the server.
Ver. 1.0
Slide 14 of 41
Solution:
To make the page interactive and enable users to interact with the Web page while the album details are retrieved, you need to perform the following steps:
1. Modify the Albums page. 2. Execute the application.
Ver. 1.0
Slide 15 of 41
AJAX-enabled Web applications mainly consist of a client-side script that is processed by the Web browser. When a user interacts with an ASP.NET AJAX-enabled application, it raises some client events. These events are handled at the client side and are called client life-cycle events. Client events are raised by the classes present in the Microsoft AJAX Library. The two main Microsoft AJAX Library classes that raise events are:
Application PageRequestManager
Ver. 1.0
Slide 16 of 41
The following table lists the client events of the Application class that are raised in AJAX-enabled Web pages.
Event Sys.Application.init Description Raised after all scripts have been loaded in the Web browser. You can use this event to add your custom component to the Web page. This event is raised only when the page is rendered for the first time. Raised after all scripts have been loaded in the Web browser and all the objects in the application are initialized. This event is raised for all postbacks to the server, including the asynchronous postbacks. Raised before all objects are disposed and before the window.unload event of the Web browser window occurs. Raised when a property of a component changes. To raise this event, you need to call the Sys.Component.raisePropertyChange method in a set accessor. Raised when the Application instance is disposed.
Sys.Application.load
Sys.Application.unload
Sys.Component.propertyChanged
Sys.Component.disposing
Ver. 1.0
Slide 17 of 41
The following table lists the client events of the PageRequestManager class that are raised in the AJAX-enabled Web pages.
Event Sys.WebForms.PageRequestManagerint ializeRequest Sys.WebForms.PageRequestManagerbeg inRequest Description Raised before an asynchronous request starts. You can use this event to cancel a postback. Raised before an asynchronous postback starts and till the postback is sent to the server. If a postback is already processing, the other postback is stopped by using the abortPostBack method. Raised after the response from the server to an asynchronous postback is received by the Web browser, but before any content on the page is updated or displayed. Raised after all content on the page is refreshed, as a result of either a synchronous or an asynchronous postback. Raised after the response for an asynchronous postback is processed and the page is updated, or during the processing of the response if there is an error. If an error occurs, the page is not updated.
Sys.WebForms.PageRequestManagerpag eLoading
Ver. 1.0
Slide 18 of 41
In AJAX-enabled Web applications, the Web service is called by using client-side scripts. To enable client scripts to communicate asynchronously with the server, ASP.NET AJAX provides the asynchronous communication layer. The communication layer enables a client application to call Web services by using JavaScript. The asynchronous communication layer acts as an intermediary layer between the browser and the server. It uses the XMLHTTP object to communicate asynchronously.
Ver. 1.0
Slide 19 of 41
Slide 20 of 41
JSON:
Is a standard and default format used for serialization by the asynchronous communication layer. Makes the interaction between the client and the server easy by eliminating the need for the client script to construct request. Is the ideal format for data exchange for AJAX-enabled Web applications. Can also be used to exchange or store structured information as text.
Ver. 1.0
Slide 21 of 41
Ver. 1.0
Slide 22 of 41
Problem Statement:
The AlbumDetails.aspx page shows the reviews for the album that is selected by the user. These reviews are provided by a Web service. You need to call the Web service in the MusicMania website.
Ver. 1.0
Slide 23 of 41
Solution:
To call the Web service in the MusicMania website, you need to perform the following steps:
1. Add a Web reference of the Web service. 2. Modify the AddReviews.aspx.cs file. 3. Execute the application.
Ver. 1.0
Slide 24 of 41
Web applications are accessed by people from different countries, cultures, and regions. Applications need to be internationalized to accommodate users from different countries and to enable them to use the website efficiently. International applications should be customizable according to the preferences of users belonging to different nations, cultures, or regions. The development of an international application goes through the following phases:
Globalization Localizability Localization
Ver. 1.0
Slide 25 of 41
Application developers need to attend to locale considerations when they develop international applications. The factors that need to be considered while designing an internationalized application are:
Language Issues Formatting Issues String-related Issues User-interface Issues
Ver. 1.0
Slide 26 of 41
The structure of an application that is created with internationalization in mind is divided into the following two blocks:
Data block: Contains user-interface resources, such as the text on Label controls that are to be translated into various languages. Code block: Contains the application code or the executable part of an application that is applicable for all cultures/locales.
The .NET Framework represents different cultures across the world by using a culture code. A culture code consists of two parts, a two-letter language code and an optional two-letter country/region code. The general format of the culture code is: <Language code>-<Country/Region code>
Ver. 1.0
Slide 27 of 41
The following table lists some culture codes and their descriptions.
Culture Code En Description Specifies English language, no region
en-CA
fr-FR De Zh-CN de-DE
Ver. 1.0
Slide 28 of 41
Culture codes that only specify a language are called neutral cultures, whereas culture codes that specify a language as well as a region are called specific cultures. To implement globalization in an application, you need to include the System.Gloablization namespace in your application. The System.Gloablization namespace provides classes that define culture-related information, such as the language, country, calendars, and formats. Two important classes included in the System.Gloablization namespace are:
CultureInfo: Provides information about a specific culture. RegionInfo: Contains information about a country/region.
Ver. 1.0
Slide 29 of 41
The following table lists some of the commonly used properties of the CultureInfo class.
Property CurrentCulture Description Returns an instance of the CultureInfo class that represents the culture for the current thread. Returns an instance of the CultureInfo class that represents the current culture used by the Resource Manager to look for culturespecific resources at run time. Returns the name of the culture in the <Language code>-<Country/Region code> format. Returns a Boolean value indicating whether the culture represented by the CultureInfo object is a neutral culture. Gets or sets a NumberFormatInfo object that defines the appropriate format of displaying numbers, currency, and percentage.
CurrentUICulture
Name
IsNeutralCulture
NumberFormat
Ver. 1.0
Slide 30 of 41
The following table lists some of the commonly used methods of the CultureInfo class.
Method CreateSpecificCulture Description Creates a CultureInfo object that represents the specific culture that is associated with the specified name. Returns a read-only instance of a culture. Gets a list of supported cultures filtered by the specified type. Returns an object that represents the format of a specified type. For example, this method will return an object representing the format of the date when the specified type is date/time.
Ver. 1.0
Slide 31 of 41
CurrentRegion
IsMetric
Ver. 1.0
Slide 32 of 41
Ver. 1.0
Slide 33 of 41
Problem Statement:
The top level management at MusicMania has decided to open a new store in France. The management wants the website to be customized for French users. For this, the information displayed on the website needs to be in French language. In the initial phase, this functionality is to be implemented only on the home page so that the welcome message is displayed in French on the home page when the page is accessed by a user whose browser settings specify French as the preferred language.
Ver. 1.0
Slide 34 of 41
Solution:
To solve the preceding problem, you need to perform the following steps:
1. Modify the Home page. 2. Verify the application.
Ver. 1.0
Slide 35 of 41
To change the format of date, time, or currency values depending on the current culture, you need to specifically write code for implementing the same. Some date formats, and their corresponding format characters are listed in the following table.
Date Format Short Date Long Date Full Date and Time (Long date and short time) Full Date and Time (Long date and long time) Short Time Long Time Format Character d D f F t T Format Pattern for en-US Culture MM/dd/yyyy dddd, dd MMMM yyyy dddd, dd MMMM yyyy HH:mm dddd, dd MMMM yyyy HH:mm:ss HH:mm HH:mm:ss
Ver. 1.0
Slide 36 of 41
The following code snippet demonstrates how to use a different format for displaying a date depending on the current culture:
protected void Page_Load(object sender, EventArgs e) { DateTime dt = DateTime.Now; CultureInfo USCulture = new CultureInfo("en-US"); CultureInfo FrenchCulture = new CultureInfo("fr-FR"); if (CultureInfo.CurrentCulture.Equals (FrenchCulture)) Label2.Text = dt.ToString("d", FrenchCulture); else Label2.Text = dt.ToString("d", USCulture); }
Ver. 1.0
Slide 37 of 41
Client events are raised when a user interacts with an ASP.NET AJAX-enabled application. Client events are raised by the classes present in the Microsoft AJAX Library. The two main Microsoft AJAX Library classes that raise events are:
Application PageRequestManager
Ver. 1.0
Slide 38 of 41
The ASP.NET AJAX architecture provides an asynchronous communication layer that enables a Web browser to call the Web service methods by using JavaScript. JSON is a standard and default format used for serialization by the asynchronous communication layer. A custom client script can be created and integrated with an AJAX-enabled ASP.NET application as:
Inline script. External java script file. Script embedded as a resource in an assembly.
Ver. 1.0
Slide 39 of 41
The process of making an application ready for international users is called internationalization. The phases that are involved in developing an internationalized application are:
Globalization Localizability Localization
The factors that need to be considered while designing an internationalized application are:
Language issues Formatting issues String-related issues User-interface issues
Ver. 1.0
Slide 40 of 41
The System.Gloablization namespace provides classes that define culture-related information, such as the language, country, calendars, and formats. The two important classes included in the System.Gloablization namespace are:
CultureInfo RegionInfo
Ver. 1.0
Slide 41 of 41