ASP.NET

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

Posted on

Asp.net with silverlight Question Answer

Q.1 What is Silverlight? Why it is introduced?

A: Sivlerlight is a web-based technology that allows you to develop

 

Posted By-: Vissicomp Technology Pvt. Ltd.

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

C#.NET

Posted on

Overriding methods:

In method overriding we can override a method in base class by creating similar method in derived class this can be achieved by using inheritance principle and using “virtual & override” keywords.

If we want to override base class method then we need to declare base class method with “virtual” keyword and the method which we created in derived class to override base class need to declare with “override” keyword like as shown below :

 

using System;

namespace Demo

{

class SampleA

{

public virtual void Show()

{

Console.WriteLine(“Sample A Test Method”);

}}

class SampleB:SampleA

{

public override void Show()

{

Console.WriteLine(“Sample B Test Method”);

}}

class Program

{

static void Main(string[] args)

{

SampleA a=new SampleA();

SampleB b=new SampleB();

a.Show();

b.Show();

a = new SampleB();

a.Show();

Console.ReadLine();}}}

 

Output:

 

Sample A Test Method

Sample B Test Method

Sample B Test Method

 

Posted By-: Vissicomp Technology Pvt. Ltd.

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