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

Namespaces

Posted on Updated on

NAMESPACE

  • Namespace is a collection of different classes. At times you need to create an application that uses various classes belongs to other application also. Some of these classes can be having the same name.
  • To avoid the problem of same name, .NET uses namespaces that are the collections of classes. All the applications that are created in .NET are developed using classes from the system namespace.
  • This  is  the  parent  namespace  of  all  the  namespaces  used  in .NET. Table 2 describes some fundamental namespaces used in .NET.
  • Below table shows a List of Namespaces

Namespaces

Description

          Using System 

Provides the classes for commonly used data types, events, and exceptions

          Collections

provides  different  types  of  classes  and  interfaces  to  create collection  of  objects,  such  as  list,  queues,  hash  tables,  and arrays

          Data

provides  the  classes  that  enable  you  to handle  data  from different data sources, such SQL or Oracle

          Data.oleDB

provides the classes that support the OLEDB .NET provider

          Data.Sqlclient

provides the classes that support the SQL server .NET provider

          Diagnostics

provides the classes that allow you to  debug your application step by step

          Drawing

provides  the  classes  that  allow  you  to  draw  on  a  control  or image

         Globalization

provides the classes that specify culture-related information

         IO

provides the classes that are used for data access with files

         NET

provides  interface  to  the  protocols  that  are  used  on  the internet

Posted By-: Vissicomp Technology Pvt. Ltd.

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

VISIBILITY AND ACCESS SPECIFIER

Posted on

USEFULL FOR TYBSC (IT) & TYBSC (CS) STUDENTS

VISIBILITY AND ACCESS SPECIFIER

  • The visibility of a class, a method, a variable or a property tells us how this item can be accessed. The most common types of visibility are private and public, but there are actually several other types of visibility within C#.

    (i) public – the member can be reached from anywhere. This is the least restrictive visibility. Enums and interfaces are, by default, publicly visible.

    (ii) protected – members can only be reached from within the same class, or from a class which inherits from this class.

    (iii) internal – members can be reached from within the same project only.

    (iv) protected internal – the same as internal, except that also classes which inherits from this class can reach it members, even from another project.

    (v) private – can only be reached by members from the same class. This is the most restrictive visibility. Classes and structs are by default set to private visibility.

    So for instance, if you have two classes, Class1 and Class2, private members from Class1 can only be used within Class1. You can’t create a new instance of Class1 inside of Class2, and then expect to be able to use its private members.

    If Class2 inherits from Class1, then only non-private members can be reached from inside of Class2.

Posted By-: Vissicomp Technology Pvt. Ltd.

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

 

MANAGED CODE and UNMANAGED CODE

Posted on

USEFULL FOR TYBSC (IT) & TYBSC (CS) STUDENTS

MANAGED CODE

  • The  code  that  is  executed  by  the  CLR  environment  rather  than  executed  by  the operating system is called as managed code.
  • The applications that are created using managed code automatically have CLR services, such  as  type  checking,  security,  and  automatic  garbage  collection  these  CLR compiles the applications to MSIL and not the machine code.
  • This  MSIL  along  with  the  metadata  that  attributes,  classes,  and  methods  of  the  code reside in an assembly.
  • The compilation takes place in the managed execution environment, which assures the working of the code.
  • The  benefits  provided  by  the  CLR  can  be  used  by  selecting  one  or  more  language compilers, such as visual basic, C#, visual C++, or any of the third party compilers, such as COBOL, PERL, or Eiffel.
  • The language compiler determines the syntax the must be Used by the code. When the code is complied into managed code, the compiler converts the source code into MSIL, which is central processing unit (CPU) – independent.
  • At this time, the required metadata is generated. The metadata contains the definition of types, member signature, the members in the code, and other details that the code uses at the time of execution. Next, MSIL must be converted into CPU – specific code by the JIT compiler, before the execution of the code.  The role of JIT compiler is to translate the MSIL into native code.
  • The  runtime  also  supports  another  method  of  compilation  named  install – time  code generation.  It converts MSIL into native code in a single shot by taking a larger unit of code at a time.
  • The  entire  assembly  is  converted  into  native  code  at  the  installation  time  itself.  By default, it takes care of other assemblies’ referred in this assembly. It stores the resulting native code for use when the assembly is loaded and run. Using the install – time code generation, the entire assembly that results in loading the code files more rapidly.

1

Posted By-:Vissicomp Technology Pvt. Ltd.

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