ASP.NET(C#)

ASP.NET – Ajax Control

Posted on Updated on

AJAX stands for Asynchronous JavaScript and XML. This is a cross platform technology which speeds up response time. The AJAX server controls add script to the page which is executed and processed by the browser.

However like other ASP.Net SERVER controls, these AJAX server controls also can have methods and event handlers associated with them, which are processed on the server side.

The ScriptManager Control

The ScriptManager control is the most important control and must be present on the page for other controls to work.

It has the basic syntax:

<asp:ScriptManager ID=”ScriptManager1″ runat=”SERVER“>

</asp:ScriptManager>

If you create an ‘Ajax Enabled site’ or add an ‘AJAX WEB FORM’ from the ‘Add Item’ dialog box, the web form automatically contains the script manager control. The ScriptManager control takes care of the client-side script for all the SERVER side controls.

The UpdatePanel Control:

The UpdatePanel control is a container control and derives from the Control CLASS. It acts as a container for the child controls within it and does not have its own interface. When a control inside it triggers a post back, the UpdatePanel intervenes to initiate the post asynchronously and update just that portion of the page.

For example, if a button control is inside the update panel and it is clicked, only the controls within the update panel will be affected, the controls on the other parts of the page will not be affected. This is called the partial post back or the asynchronous post back.

Example:

Add an AJAX WEB FORM in application. It will contain the script manager control by default. Insert an update panel. Place a button control along with a label control within the update panel control. Place another set of button and label outside the panel.

12

The source file is as follows:

<form id=”form1″ runat=”SERVER “>

<div>

<asp:ScriptManager ID=”ScriptManager1″ runat=”server” />

</div>

<asp:UpdatePanel ID=”UpdatePanel1″ runat=”SERVER “>

<ContentTemplate>

<asp:Button ID=”btnpartial” runat=”SERVER

onclick=”btnpartial_Click” Text=”Partial PostBack”/>

<br />

<br />

<asp:Label ID=”lblpartial” runat=”SERVER “></asp:Label>

</ContentTemplate>

</asp:UpdatePanel>

<p>

</p>

<p>

Outside the Update Panel</p>

<p>

<asp:Button ID=”btntotal” runat=”server”

onclick=”btntotal_Click” Text=”Total PostBack” />

</p>

<asp:Label ID=”lbltotal” runat=”server”></asp:Label>

</form>

Both the button controls have same code for the event handler:

string time = DateTime.Now.ToLongTimeString();lblpartial.Text = “Showing time from panel” + time;lbltotal.Text = “Showing time from outside” + time;

Observe that when the page is run, if the total post back button is clicked, it updates time in both the labels but if the partial post back button is clicked, it only updates the label within the update panel.

13

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Ajax Control

Posted on Updated on

Ajax Control

Properties of the UpdatePanel Control:

The following table shows the properties of the update panel control:

Properties Description
ChildrenAsTriggers This property indicates whether the post backs are coming from the child controls which will cause the update panel to refresh.
ContentTemplate It is the content template and defines what appears in the update panel when it is rendered.
ContentTemplateContainer Retrieves the dynamically created template container object and used for adding child controls programmatically.
IsInPartialRendering Indicates whether the panel is being updated as part of the partial post back.
RenderMode Shows the render modes. The available modes are Block and Inline.
UpdateMode Gets or sets the rendering mode by determining some conditions.
Triggers Defines the collection trigger objects each corresponding to an event causing the panel to refresh automatically.

Methods of the UpdatePanel Control:

The following table shows the methods of the update panel control:

Methods Description
CreateContentTemplateContainer Creates a Control object that acts as a container for child controls that define the UpdatePanel control’s content.
CreateControlCollection Returns the collection of all controls that are contained in the UpdatePanel control.
Initialize Initializes the UpdatePanel control trigger collection if partial-page rendering is enabled.
Update Causes an update of the content of an UpdatePanel control.

The behaviour of the update panel depends upon the values of the UpdateMode property and ChildrenAsTriggers property:

UpdateMode ChildrenAsTriggers Effect
Always False Illegal parameters.
Always True UpdatePanel refreshes if whole page refreshes or a child control on it posts back.
Conditional False UpdatePanel refreshes if whole page refreshes or a triggering control outside it initiates a refresh.
Conditional True UpdatePanel refreshes if whole page refreshes or a child control on it posts back or a triggering control outside it initiates a refresh.

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Ajax Control

Posted on

ASP.NET – Ajax Control

  • AJAX stands for Asynchronous JavaScript and XML. This is a cross platform technology which speeds up response time.
  • The AJAX server controls add script to the page which is executed and processed by the
  • However like other Net server controls, these AJAX server controls also can have methods and event handlers associated with them, which are processed on the server side.
  • The control toolbox in the Visual Studio IDE contains a group of controls called the ‘AJAX Extensions’

1

The ScriptManager Control

  • The ScriptManager control is the most important control and must be present on the page for other controls to work.

The basic syntax:

<asp:ScriptManager ID=”ScriptManager1″ runat=”server”>

</asp:ScriptManager>

If you create an ‘Ajax Enabled site’ or add an ‘AJAX Web Form’ from the ‘Add Item’ dialog box, the web form automatically contains the script manager control. The ScriptManager control takes care of the client-side script for all the server side controls.

The UpdatePanel Control:

  • The UpdatePanel control is a container control and derives from the Control class. It acts as a container for the child controls within it and does not have its own interface. When a control inside it triggers a post back, the UpdatePanel intervenes to initiate the post asynchronously and update just that portion of the page.
  • For example, if a button control is inside the update panel and it is clicked, only the controls within the update panel will be affected, the controls on the other parts of the page will not be affected. This is called the partial post back or the asynchronous post back.

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Managing State

Posted on

HTTP ( Hyper Text Transfer Protocol) is a stateless protocol. When the client disconnects from the server, the ASP.Net engine discards the page objects. This way each web application can scale up to serve numerous requests simultaneously without running out of server memory.

However, there need to be some technique to store the information between requests and to retrieve it when required. This information i.e., the current value of all the controls and variables for the current user in the current session is called the State.

ASP.Net manages four types of state:

  • View State
  • Control State
  • Session State
  • Application State

View State:

The View State is the state of the page and all its controls. It is automatically maintained across posts by the ASP.Net framework.

When a page is sent back to the client, the changes in the properties of the page and its controls are determined and stored in the value of a hidden input field named _VIEWSTATE. When the page is again post back the _VIEWSTATE field is sent to the server with the HTTP request.

The view state could be enabled or disabled for:

  • The entire applicationby setting the EnableViewState property in the <pages> section of config file
  • A pageby setting the EnableViewState attribute of the Page directive, as <%@ Page Language=”C#” EnableViewState=”false” %>
  • A controlby setting the EnableViewState property.

It is implemented using a view state object defined by the StateBag class which defines a collection of view state items. The state bag is a data structure containing attribute/value pairs, stored as strings associated with objects.

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Directives

Posted on

ASP.NET – Directives

The Implements Directive

The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.

The basic syntax for an Implements directive is:

<%@ Implements  Interface=”interface_name” %>

The Import Directive

The Import directive imports a namespace into a web page, user control pate of application. If the Import directive is specified in the global.asax, then it will apply to the entire application. If it is in a page of user control page, then it would apply to that page or control.

The basic syntax for an Import directive is:

<%@ namespace=”System.Drawing” %>

The PreviousPageType Directive

The PreviousPageType directive assigns a class to a page, so that the page is strongly typed.

The basic syntax for a sample PreviousPagetype directive is:

<%@ PreviousPageType attribute=”value”[attribute=”value” …]   %>

The Reference Directive

The Reference directive indicates that another page or user control should be compiled and linked to the current page.

The basic syntax for a sample Reference directive is:

<%@ Reference Page =”somepage.aspx” %>

The Register Directive

The Register derivative is used for registering the custom server controls and user controls.

The basic syntax for a sample Register directive is:

<%@ Register Src=”~/footer.ascx” TagName=”footer”

TagPrefix=”Tfooter” %>

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Directives

Posted on

ASP.NET – Directives

The Implements Directive

The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.

The basic syntax for an Implements directive is:

<%@ Implements  Interface=”interface_name” %>

The Import Directive

The Import directive imports a namespace into a web page, user control pate of application. If the Import directive is specified in the global.asax, then it will apply to the entire application. If it is in a page of user control page, then it would apply to that page or control.

The basic syntax for an Import directive is:

<%@ namespace=”System.Drawing” %>

The Master Directive

The Master directive specifies a page file as being the mater page.

The basic syntax for a sample MasterPage directive is:

<%@ MasterPage Language=”C#”  AutoEventWireup=”true”

    CodeFile=”SiteMater.master.cs” Inherits=”SiteMaster”  %>

The MasterType Directive

The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed.

The basic syntax for a MasterType directive is:

<%@ MasterType attribute=”value”[attribute=”value” …]  %>

The OutputCache Directive

The OutputCache directive controls the output caching policies of a web page or a user control. We will discuss this directive in details, in data caching.

The basic syntax for a OutputCache directive is:

<%@ OutputCache Duration=”15″ VaryByParam=”None”  %>

The Page Directive

The Page directive defines the attributes specific to the page file for the page parser and the compiler.

The basic syntax for a Page directive is:

<%@ Page Language=”C#”  AutoEventWireup=”true”

    CodeFile=”Default.aspx.cs” Inherits=”_Default”  Trace=”true” %>

The attributes of the Page directive are:

Attributes

Description

AutoEventWireup

the Boolean value that enables or disables Page events that are being automatically bound to methods; for example, Page_Load

Buffer

the Boolean value that enables or disables HTTP response buffering

ClassName

class name for the page

ClientTarget

the browser for which server controls should render content

CodeFile

name of the code behind file

Debug

the Boolean value that enables or disables compilation with debug symbols

Description

text description of the page, ignored by the parser

EnableSessionState

enables, disables or makes session state read-only

EnableViewState

the Boolean value that enables or disables view state across page requests

ErrorPage

URL for redirection if an unhandled page exception occurs

Inherits

the name of the code behind or other class

Language

programming language for code

Src

file name of the code behind class

Trace

enables or disables tracing

TraceMode

indicates how trace messages are to be displayed – sorted by time or category

Transaction

indicates if transactions are supported

ValidateRequest

the Boolean value that indicates whether all input data is validated against a hardcoded list of values

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com

ASP.NET – Directives

Posted on

ASP.NET – Directives

The Implements Directive

The Implement directive indicates that the web page, master page or user control page must implement the specified .Net framework interface.

The basic syntax for an Implements directive is:

<%@ Implements  Interface=”interface_name” %>

The Import Directive

The Import directive imports a namespace into a web page, user control pate of application. If the Import directive is specified in the global.asax, then it will apply to the entire application. If it is in a page of user control page, then it would apply to that page or control.

The basic syntax for an Import directive is:

<%@ namespace=”System.Drawing” %>

The Master Directive

The Master directive specifies a page file as being the mater page.

The basic syntax for a sample MasterPage directive is:

<%@ MasterPage Language=”C#”  AutoEventWireup=”true”

    CodeFile=”SiteMater.master.cs” Inherits=”SiteMaster”  %>

The MasterType Directive

The MasterType directive assigns a class name to the Master property of a page, to make it strongly typed.

The basic syntax for a MasterType directive is:

<%@ MasterType attribute=”value”[attribute=”value” …]  %>

The OutputCache Directive

The OutputCache directive controls the output caching policies of a web page or a user control. We will discuss this directive in details, in data caching.

The basic syntax for a OutputCache directive is:

<%@ OutputCache Duration=”15″ VaryByParam=”None”  %>

The Page Directive

The Page directive defines the attributes specific to the page file for the page parser and the compiler.

The basic syntax for a Page directive is:

<%@ Page Language=”C#”  AutoEventWireup=”true”

    CodeFile=”Default.aspx.cs” Inherits=”_Default”  Trace=”true” %>

The attributes of the Page directive are:

Attributes

Description

AutoEventWireup

the Boolean value that enables or disables Page events that are being automatically bound to methods; for example, Page_Load

Buffer

the Boolean value that enables or disables HTTP response buffering

ClassName

class name for the page

ClientTarget

the browser for which server controls should render content

CodeFile

name of the code behind file

Debug

the Boolean value that enables or disables compilation with debug symbols

Description

text description of the page, ignored by the parser

EnableSessionState

enables, disables or makes session state read-only

EnableViewState

the Boolean value that enables or disables view state across page requests

ErrorPage

URL for redirection if an unhandled page exception occurs

Inherits

the name of the code behind or other class

Language

programming language for code

Src

file name of the code behind class

Trace

enables or disables tracing

TraceMode

indicates how trace messages are to be displayed – sorted by time or category

Transaction

indicates if transactions are supported

ValidateRequest

the Boolean value that indicates whether all input data is validated against a hardcoded list of values

Posted By-: Vissicomp Technology Pvt. Ltd.

Website -: http://www.vissicomp.com