Asp Dot Net Presentation 6fp19

  • ed by: Nadikattu Ravikishore
  • 0
  • 0
  • July 2021
  • PDF

This document was ed by and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this report form. Report 3i3n4


Overview 26281t

& View Asp Dot Net Presentation as PDF for free.

More details 6y5l6z

  • Words: 15,489
  • Pages: 311


Master pages and themes • Need for master page and themes arise when u want to create web pages that contain some common elements and u want to customize the properties of different controls like buttons,textbox and labels. • For eg, when u want to create a web site for ur company in which all the web pages have as header stating the company name and all buttons on the web page are of blue color. We can create this web site by using master pages and themes.

• Suppose u want to include a navigation bar at a common place in all the web pages of ur website. If u are not using a master page, you will have to copy and paste the code for the commmon navigation bar on each page, which is obvious a tedious and time consuming job. • Also if later we want to change the navigation bar then the changes has to be made with all the web pages. • So, however if we are using master pages , we just need to include the navigation bar code in the master page and all the web pages will inherit it.

• To create master page for a website, identity the controls that you want to display on all the pages then add these control to master page. Then create the contentplaceholder for the master page to plcae the content of the web pages. When this web site is executed , then the layout of the master pageand the content in contentplaceholders are merged to display the output web page.

• Themes is also a new feature of ASP.NET 2.0 that helps maintain a common look and feel across or several pages of your web site. Themes are needed when u want to keep the style and layout information file separate from other web site files. Themes can include images and skin files,the skin files set the visual properties of ASP.NET controls

Working with master page • Right click the web application and select add newitem. Select the master file option from the template. • Design the master page with the control u want . • Add new webpage and slect theuse mater page option . It waill ask for u to select the master page. So select ur master page and say ok.

• You can see that the default page acquires the properties of master page. MODIFYING CONTENT ON THE MASTER PAGE FROM CONTENT PAGE: • U can update the content on the masterpage by finding the control which needs to be modified on the master page from the content page.

• Place calendar control on the master page. • Now add new page default.aspx and place textbox,label and button on the form. • Write the following lines of code on button_click event protected void Button1_Click(object sender, EventArgs e) { try { Calendar cal; cal = (Calendar)Master.FindControl("Calendar1"); if (cal != null) { cal.VisibleDate = Convert.ToDateTime(TextBox1.Text); cal.SelectedDate = Convert.ToDateTime(TextBox1.Text); } } catch { Response.Write("invalid format"); } }

• Run the application. Enter date in mm/dd/yy format in the text box and click the update button. • U will c that the the calender date has changed to the date provided with textbox.

Getting the label’s text value in the content page:

Creating themes • Applying built-in themes to web pages is quite easy, as u just need to specify the name of the theme with the theme attributeof the page directive. However we can also apply custom themes to web pages. For that we need to create a theme first.

steps • Right-click the web site name on the solution explore and select add ASP.NET folder | theme from the shortcut menuto add App_Theme foleder. A subfolder named Theme1 is automatically created inside the App_Theme folder. • Right click the theme1 folder nd select Add new item option from the menu to display add new item dialog box. • Select the skin file template option and specify the name of the skni as theme.skin and click add button.

• Now we have created a new skin file we will define the style properties inside it. Add the following line of code to the theme.skin file. •

protected void Page_PreInit(object sender, EventArgs e) { Page.Theme = Request.QueryString["theme"]; }

STATE MANAGEMENT Purpose State management is the process by which you maintain state and page information over multiple requests for the same or different pages. Types of State Management There are 2 types State Management: 1. Client – Side State Management 2. Server – Side State Management

• 1. Client – Side State Management This stores information on the client's computer by embedding the information into a Web page, a uniform resource locator(url), or a cookie. The techniques available to store the state information at the client end are listed down below: a. View State – Asp.Net uses View State to track the values in the Controls. You can add custom values to the view state. It is used by the Asp.net page framework to automatically save the values of the page and of each control just prior to rendering to the page. When the page is posted, one of the first tasks performed by page processing is to restore view state

Design the page as below

Code for .aspx.cs page Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click ViewState("name") = TextBox1.Text.ToString() ViewState("city") = TextBox2.Text.ToString() ViewState("color") = TextBox4.Text.ToString() Label4.Text = "u data is saved in viewstate" End Sub

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click Dim v_viewState As String v_viewState = Request.Form("__VIEWSTATE") Response.Write(v_viewState) Dim nm, ct, cl As String 'TextBox1.Text = ViewState("name").ToString 'TextBox2.Text = ViewState("city").ToString 'TextBox4.Text = ViewState("color").ToString nm = ViewState("name").ToString ct = ViewState("city").ToString cl = ViewState("color").ToString Label4.Text = "ur name is" & nm & "city:" & ct & "color" & cl End Sub

• b. Control State – If you create a custom control that requires view state to work properly, you should use control state to ensure other developers don’t break your control by disabling view state. c. Hidden fields – Like view state, hidden fields store data in an HTML form without displaying it in the 's browser. The data is available only when the form is processed.

Place textbox,button and hidden control on the page. Set the value property for hidden to “sellglobally” Button_click(………) { TextBox1.Text = myid.Value; }

• d. Cookies – Cookies store a value in the 's browser that the browser sends with every page request to the same server. Cookies are the best way to store state data that must be available for multiple Web pages on a web site.

Place 2 textbox,label and button on the page

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "orbit" And TextBox2.Text = "sell" Then Response.Redirect("welcome.aspx") Else Dim obj As HttpCookie obj = Request.Cookies("aaa12") If obj Is Nothing Then obj = New HttpCookie("aaa12") obj.Value = 1 Else obj.Value += 1 End If Response.AppendCookie(obj) Label1.Text = "No of Attempts: " & obj.Value End If End Sub

• e. Query Strings - Query strings store values in the URL that are visible to the . Use query strings when you want a to be able to e-mail or instant message state data with a URL.

Page1 code: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click Dim id As Integer id = TextBox1.Text Response.Redirect("Default.aspx?Id=" & id) End Sub Page2 code: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click If Request.QueryString IsNot Nothing Then TextBox1.Text = Request.QueryString("id").ToString Else TextBox1.Text = "" End If End Sub

2. Server – Side State Management •

a. Application State - Application State information is available to all pages, regardless of which requests a page. • Application State: ASP.NET allows you to save values using application state, a global storage mechanism that is accessible from all pages in the Web application. Application state is stored in the Application key/value dictionary. Once you add your application-specific information to application state, the server manages it, and it is never exposed to the client. Application state is a great place to store information that is not -specific. By storing it in the application state, all pages can access data from a single location in memory, rather than keeping separate copies of the data. Data stored in the Application object is not permanent and is lost any time the application is restarted.

• ASP.NET provides three events that enable you to initialize Application variables (free resources when the application shuts down) and respond to Application errors: a. Application_Start: Raised when the application starts. This is the perfect place to initialize Application variables. b. Application_End: Raised when an application shuts down. Use this to free application resources and perform logging. c. Application_Error: Raised when an unhandled error occurs. Use this to perform error logging.

Global.asax void Application_Start(object sender, EventArgs e) { // Code that runs on application startup Application["x"] = 0; } void Session_Start(object sender, EventArgs e) { // Code that runs when a new session is started Application["x"] = int.Parse(Application["x"].ToString()) + 1;

}

Default.aspx.cs public partial class globaldemo : System.Web.UI.Page { protected void Button1_Click(object sender, EventArgs e) { Response.Write(Application["x"]); } }

• b. Session State – Session State information is available to all pages opened by a during a single visit.

Both application state and session state information is lost when the application restarts. To persist data between application restarts, you can store it using profile properties.

• You can define the session by using session("valueName") = value • And You can retrieve the value in label (for Example) By Label1.text = session("valueName")

webform1.aspx.cs Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Session("msg") = txtuid.Text Response.Redirect("webform2.aspx") End Sub

webform2.aspx.cs Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Label1.Text = "Welcome to " & Session("msg") End Sub

Security Authentication and authorization: Authentication is a process that determines the identity of a . After a has been authenticated, a developer can determine if the identified has authorization to proceed. It is impossible to give an entity authorization if no authentication process has been applied

Authorization Authorization is the process of determining whether an authenticated is permitted access to any part of an application, access to specif points of an application, or access to specified datasets that the application provides.

The node: You can use the node in the application’s web.config file to set the type of authentication ur Asp.NET application requires. <system.web> <deny s="?"/>

• Provider Windows

Forms

port

description windows authentication is used together with IIS authentication. This is default setting. request that are not authenticated are redirected to an html form using HTTP clientside redirection. The provide his information and submits the form. a centeralized authentication service provided by Microsoft that offers single and core profile services for member site .

Windows-based authentication Windows –based authentication is handled between the windows server where

Form based authentication Is a popular mode of authenticating s to access an entire application or specific resources with in an application. Using it enable u to put the form directly in the application so thet athe end used simply enters his unm/pwd into an HTML form contained with the browser itself. <system.web> <deny s="?"/>

U must apply this tructure to the web.config file. First using the elementg ,u r denying access to the applicxation to all anonymous s. Only authenticated uer are allowed to access anty page contained with the application. If the requestoir is not autrhenticated, what is defines in the element is pt into action. The value of the mode attribute is set to forms to employ form-based authentication/. . The next attribute specified is the URL, which points to the page that containg the application form. The final attribute is path. It simply specifies the location in which to save the cookie used to persisit the authorized ’s access token. Name : name is assignes to the cookie saved in order to the from request to request. The default value is .ASPXAUTH.

protected void Button1_Click(object sender, EventArgs e) { if (TextBox1.Text == "scott" && TextBox2.Text == "tiger") FormsAuthentication.RedirectFromPage(TextBox1.Text, false); else Response.Write("invalid uername/"); } Note:RedirectFromPage takes two arguments. First is the name of the , used for cookie authentication purposes. The second argumentspecifies whether a durable cookie should be issued. If set to true, the end does not need to again to the application from one browser session to the next. Web.config file <system.web> <deny s="?"/>

Authenticating against values contained in the web.config file Previous eg is not the best approach fpr dealing with unm and pwd offered for authentication. It is never good idea to hardcode these things directly into ur application. The
element in web.config that u worked can also take sub-element . The sub-element allows you to specify unm and pwd combination directly in the web.config file.

Modify web.config file to add unm/pwd values < name ="scott" =“tiger"/> <deny s="?"/>

The elemebnt has been included to add unm and pwd to the configuration file. It takes single attribute-Format . The possible values of Format are clear,MD5,SHA1. •

Clear: are stored in clear text. The is compared directly to this value without further tranformation.



MD5 : are stored using a message Digest 5(MD5) hash digest. When credentials are validated, the worsd is hashed using the MD5 algorithm and compared equality with this value. Clear text are never is never stored or compared.



SHA1 : s are stored using SHA1 hash digest. When credentials are validated, the is hashed using the SHA1 algorithm and compared equality with this value. Clear text are never is never stored or compared.

Changing .aspx page to work with web.config file if (FormsAuthentication.Authenticate(TextBox1.Text, TextBox2.Text)) { FormsAuthentication.RedirectFromPage(Text Box1.Text, true); } else { Response.Write("invalid "); }

Web services • A Web Service (XML Web Service) is a unit of code that can be activated using HTTP requests. Stated another way, a Web Service is an application component that can be remotely callable using standard Internet Protocols such as HTTP and XML. One more definition can be, a Web Service is a programmable URL. Web Services came into existence to deliver distributed computing over the Internet. A major advantage of the Web services architecture is, it allows programs written in different languages on different platforms to communicate with each other in a standards-based way. Simply said, a Web service is a software service exposed on the Web through SOAP, described with a WSDL file and ed in UDDI.

Why XML Web Services? • Today, available technologies like Component Object Model (COM), Remote Method Invocation (RMI), Common Object Request Broker Architecture (CORBA) and Internet Inter-ORB Protocol (IIOP) are used to package application logic into reusable components and are called remotely across multiple platforms. The Internet today consists of tremendous number of heterogeneous systems and a key limitation of all the above said technologies is they are not easily interoperable with these different systems and that limits their effectiveness as a standard method for programming the Web. This is because of the dependencies of these technologies on a particular language or a particular Operating System or Object-model specific protocols. Web Services on the other hand are very different when compared to the said technologies as they are built upon widely accepted standards that can interoperate easily on the Internet. A key to the success of Web Services is that they use a text-based messaging model to communicate which allows them to operate effectively on different platforms.

• SOAP • We hear a lot about SOAP these days. Simple Object Access Protocol (SOAP) is a lightweight protocol for exchange of information in a decentralized, distributed environment.

UDDI • Universal Discovery Description and Integration is like the "Yellow Pages" of Web services.

profiles • profile: you can make web-site more friendly by customizing the web site according to the preferences of the s visiting the web-site.. For e.h you can customize a shopping web site to display a shopping cart consisting of the item frequently purchased by a , when the visits site. For this we need to collecte the information of the , visiting the web site.

• A profile is a collection of various properties. A property specifies the information that is to be gathered, when the visits the site. For e.g. we can deifne first name,last name and the page visits properties in a profile to store the detaild of the and information about web site usage. • The advantage of using profile to store the information permanently. So the information stored in the profile of is not lost when the leaves the web site.

Anonymous profiles: • There could be a situation where a number of s would like to explore your website for free before actually ing to it. We need to provide attractive profile to these”surf for free” to make them ed s. These surf for free s are called anonymous s as they do not have valid name and .

• Note: by default the cookie gets expires after a time period of 70 days. This time period renewed every time a visits the web site.

Authenticated • When surf-for free of website become ed , you need to display different data to them. • The authenticated profiles are displayed to the authenticated s when they log on to the site using valid UNM and PWD. By default all the s are authenticated profiles because the enabled attribute of the element is false by default.

Defining profiles: • To define the profiles, you need to define the properties for the profile in either the machine.config file .or web.config configuration.a property is defined with the element, which is available in the <property> element.

Web.config (working with the single profile[authenticated]) <profile> <properties>

Defining multiple profiles • We’ve used only a single type of profile that is common for all s of an application. It is also possible to define multiple types of profiles for the end s.. These multiple profiles exhibits different types of s, such as anony. And authenticated.

Web.config <profile> <properties>

• • • • • • • • • • • • •

protected void b1_Click(object sender, EventArgs e) { if (Page..Identity.IsAuthenticated) { Profile.fnm = t1.Text; Profile.snm = T2.Text; l1.Text = Profile.fnm; L2.Text = Profile.snm; } Profile.state = T3.Text; L3.Text = Profile.state; } }

caching • Caching is a technique to store data temporaily in momory. For. Eg. Application needs to query a databse which contain I million records after every 4 sec for the same kind of result. Ur DB will get updated in a time interval of say, an hour. • So, the dat retrieved from the DB will remain the same for approx. 50 min. , as the DB will be updated only after one hour. So querying the same DB after every 4 seconds will increase the network traffic and the load on the DB server.

• Let’s if we uses caching to store the results we get after running the query on the DB. So we cache the data for a fixed period of time say 50 min., then once the first qry is executed, the results will be stored in cache. In the nxt 50 min. the same type of req. for the data will get the data from the cache itself without running the qry again on 1 million of record.

ASP.NET provides 3 kinds of caching techniques • Output caching(page level caching) • Partial caching • Data caching • Output caching: in output caching the complete HTML output of a rendered ASP.NET page is stored in the cache and the subsequent requests for the same page is sent from the cache itself.

• We can easily implement output caching by just adding the @outputcache directive in the web page as follows: • <%@ outputcache duration=“10” varybyparam=“none”%> • Duration is in seconds. • Create application and add a label on the default.aspx page. • Code for the code-behind file: protected void Page_Load(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); }

Using output caching with varybyparam • The varybyparam attribute is used to cache different copies of the same page when they are generated dynamically based on the parameters received. • Create a page with label,textbox and button.

Code for default.aspx.cs protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { name.Visible = false; Label1.Visible = false; Button1.Visible = false; Label2.Visible = true; Label2.Text = "output of this page was cached for " + name.Text + ".the current time is :" + DateTime.Now.ToString(); } }

Write the lines in the source code. • <%@ OutputCache Duration ="10" VaryByParam ="Name" %>

Partial-page caching

• It’s not always that you require the cache for the complete page. This is also called partial-page or fragment caching.Generally used for caching the control. • Design the control by keeping the label. • Label1.text=“control time is:” + datetime.now.tostring(); • With source code ( control page)--• <%@ outputcache duration=“10” varybyparam=“none” %> • Desing the new web page and drag the control on the page and also one label. • Label1.text=“base time is:” + datetime.now.tostring();

Data caching •



Data caching is useful when u need to cache your own custom data into cache. For e.g. , you need to cache a dataset which can be used later somewhere in ur application. There are 3 main tasks for data caching:

1. Adding items to cache: cache(“myvalue”)=value 2. Retrieving data from cache:value=cache(“myvalue”) 3. Deleteing items from cache: cache.remove(“mydata1”)

Using data caching: • In this example we will populate the dataset from the XML file and store this dataset in cache using the file based dependency. So whenever our original XML file changes, the cached dataset will populate again. • Keep the gridview control and label on the page.

Code for default.aspx.cs • • • • • • • • • • • • • • • •

DataSet ds = new DataSet(); protected void Page_Load(object sender, EventArgs e) { if (Cache["mycache"] == null) { ds.ReadXml(Server.MapPath("data1.xml")); Cache.Insert("mycache", ds, new System.Web.Caching.CacheDependency(Server.MapPath("data1.xml "))); Label1.Text = "cache generated"; } else { Label1.Text = "using pregenerated cache"; } GridView1.DataSource = Cache["mycache"]; GridView1.DataBind(); }

State management • By using states with web application we can preserve the state of the web application both at the server and at the client side. • The state of the web application actually stores the changes that has been made to the web application. . • If u are not using states then these changes gets discarded.

• Storing states is optional. But under certain circumstances, it becomes quite imperative to use states with your applications. For e.g. it is necessary to store states for web applications, such as e-commerce shopping site or an intranet site of a company to keep track of the requests, such as the items chosen by the on a shopping site. • The various state types include application,session, and view.

Application state • It is used to store the data corresponding to the global variables of an ASP.NET web application. The data in the application-state is stored once and read many times. The application-state uses the HttpApplicationstate class to store and share the data throughout the application. The data stored in the application state is accessible to all pages of an ASP.NET web application and the data is same for all the s accessing the web applications.

Session - state • Each client accessing a web application maintains a distinct session with the web server, and there’s also specific information associated with each of these sessions. Session-state is used to store this information. The session-state is defined in the <sessionstate> section of the web.config file and stores the data specific to a session in session variables. Different session variables are created for each sessions. Also, the session variables can be accessed from any page of the web application. When a access the web page a session ID for the is created. The session ID is transferred between the server and the client over the HTTP protocol using cookies.

View state • The view-information stores the page specific information, when a page is posted back to the server. When the page is processed, the current state of the web page and control is hashed into string and saved as a hidden field. Such a state of the web page s called view-state and is defined as a hidden field on a web page.

Global.asax • The global.asax file resides in the root directory of an ASP.NET web application and is called ASP.NET application file. T contains the code that is executed when the certain events, such as start of an application or error in an application are raised by the web application.

ASP.NET AJAX AJAX is an acronym for Asynchronous JavaScript and XML and in web application development, it signifies the capability to build applications that make use of XMLHttpRequest object.

Understanding the need for AJAX: Today, if you are going to build an application, you have the option of creating a thickclient or a thin-client application. A thick-client applications is typically a compiled executable that end can run in the confines of their own environment.. Generally, the technology to build this type of application is the windows Forms technology. A thin-client application is typically one that has its processing and rendering controlled at a single point and the results of the view are sent down as HTML to a browser to be viewed by a client. To work, this type of technology generally requires that the end- be connected to the internet or intranet of some kind.

Each type of application has its pros and cons. The thick-client style of applications is touted as more fluid and more responsive to an end ’s actions. In a web based application, the complaint has been for many years that every action by an end takes numerous seconds and results in a jerky page refresh. In trun, the problem with the thick client style of application has always been that the application sits on the end ’s machine and any patches or updates to the application require you to somehow upgrade each and every machine upon which the applications sits.. ASP.NET AJAX in particular is further removing any of the negatives that would have stopped you from building an application on the web. ASP.NET AJAX makes your web applications some more fluid that ever before. AJAX –enabled applications are responsive and give the end immediate and direction through the workflows that you provide.

Before AJAX Windows Server Asp.NET Processing engine

request

response

End ’s internet browser

End ’s client computer

So, what AJAX doing to ur web application? First off, let’s take a look at what a web page does when it does not use AJAX. Figure shows a typical request and response activity for a web application. In this case, an end makes a request from his browser to the application that is stored on your web server. The server processes the request and the Asp.NET renders a page, which is then sent to the requestor as a response. The response, once received by the end , is displayed with the end ’s browser. From here , many events that take place within the application instance as it sits within the end ’s browser causes the complete request and response process to reoccur. For instance, he end might click the radio button, a check box, a button, a calendar or anything else and this causes the entire web page to be refreshed or a new page to be provided.

AFTER AJAX Windows Server Asp.NET Processing engine

request

response

Asynchronous request

End ’s internet browser ASP.NET AJAX Library End ’s client computer

Asynchronous response

On the other hand, an AJAX-enabled web page includes a javascript library on the client that takes care of issuing the calls to the web server. It does this when it is possible to send a request and get response for just part of the page and using script; the client library updates that part of the page without updating the entire page. By just processing part of the page, the end experiences what some people term “fluidity” in a page,which makes the page more responsive. The amount of code required to update just a portion of a page is less and produces the responsiveness the end expects. Figure demonstartes that the first thing that happens is the entire page is delivered in the initial request and response. From here, any partial updates required by the page are done using the client script library. This library can make asynchronous page requets and updates just the portion of the page that needs updating. One major advantage to this is that a minimal amount of data is transferred for the update to occur. Updating a partial page is better than recalling the entire page for what is just a small change to the page

AJAX is dependent upon a few technologies in order for it to work. The first is the XMLHttpRequest object. This object allows the browser to communicate to a abck-end server and has been available in the Microsoft world since internet explorer 5 through MSXM ActiveX component. The other major component is JavaScript . This technology provides client-side initiation to communication with the backend services and take care of packaging a message to send to any server-side services. Another aspect of AJAX is for DHTML and DOM(Document Object Model). These are the pieces that will change the page when the asynchronous response is received from the server. Finally the last piece is the data that is being transferred from the client to the server. This is done in XML or, more important JSON(JavaScript Object Notation)

Building a simple Asp.NET3.5 page with AJAX •Design the page where two of the controls to add are typically Asp.NET server control-label and button server control. •In addition to these controls, you are going to have to add some Asp.NET AJAX controls. •From AJAX extension, add script manager server control to the top of the page and include the second label and button control inside the update control. •Update control is a template server control and allows you to include any number of items with in it. •The page will look like this:

Add the lines of code: protected void Button2_Click(object sender, EventArgs e) { Label1.Text = DateTime.Now.ToString(); Label2.Text = DateTime.Now.ToString(); } Note: when u will click button2(ajax button) the time with label2 will change and not with label1 as the label1 is outside the update.

The ScriptManager control •The ScriptManager control is central to AJAX functionality in ASP.NET. The control manages all ASP.NET AJAX resources on a page. This includes ing Microsoft AJAX Library scripts to the browser and coordinating partial-page updates that are enabled by udate controls •The scriptmanager control takes acre of managing the JavaScript libraries that are utilized on your page as well as marshalling te massage back and forth between the server and the client for the partial page rendering process. •The marshalling of the messages can be done using either SOAP or JSON through the script manager control.

Update control •By udate controls, you can refresh selected parts of the page instead of refreshing the whole page with a postback. •This is referred to as performing a partial-page update. •An ASP.NET Web page that contains a ScriptManager control and one or more Update controls can automatically participate in partial-page updates, without custom client script. •When you use an Update control, the page behavior is browser independent and can potentially reduce the amount of data that is transferred between client and server.

The following examples show different scenarios for using the ScriptManager control.

Enabling Partial-Page Updates The following example shows how to use the ScriptManager control to enable partial-page updates. In this example, a Calendar and a DropDownList control are inside an Update control. By default, the value of the UpdateMode property is Always, and the value of the ChildrenAsTriggers property is true. Therefore, child controls of the cause an asynchronous postback

public partial class Default2 : System.Web.UI.Page { public void DropDownSelection_Change(Object sender, EventArgs e) { Calendar1.DayStyle.BackColor = System.Drawing.Color.FromName(DropDownList1.SelectedItem.Value); } protected void Calendar1_SelectionChanged(object sender, EventArgs e) { Label1.Text = Calendar1.SelectedDate.ToString(); Label2.Text = Calendar1.SelectedDate.ToString(); } }


Red Green Blue Yellow Silver



Update control..contd…….. The Element There are a couple of ways to deal with the controls on the page that initiates the asynchronous page pastbacks. e.g.: putting the trigger inside of the Update control Put the label and the button control inside the update control




protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "this button was clicked on :" + DateTime.Now.ToString(); } In this case ,label and button server controls are contained within the update server control. The element has two possible subelements: and the element. Any content that needs to be changed with the asynchronous page postbacks should be contained within the section of the update control. By default, any type of control trigger(normally page postback ) that is contained within the section instead causes the asynchronous page postback.. That mans, the button on the page will trigger an asynchronous page postback instead of a full –page postback. Each click on the button changes the time displayed in the label control.

The element Previous example demonstrates one of the big issues with this model: when the synchronous poastback occurs, you are not only sending date/time value for the label control, but you are also sending back the entire code for the button that is on the page. The code that is sent back to the client via asynchronous postback shows that the entire section contained within the update control is reissued. You can slim down your web pages by including only portions of the page that are actually updating. If you take the button outside of the section of the update control, then you have to include a section within the control.

Using trigger to cause asynchronous page postback