Ajax controls, Tree view control, Event Driven Programming, client side state management technique

Q7) Write short notes on following (ANY THREE):
a) Ajax controls.
b) Tree view control.
c) Event Driven Programming.
d) Any two client side state management technique


Ans.

a) Ajax controls.

The following ASP.NET AJAX server controls that come with ASP.NET
ScriptManager
ScriptManagerProxy
Timer
UpdatePanel
UpdateProgress

ScriptManager Control

If you want to use ASP.NET AJAX control than you must have ScriptManager Control on the page. The ScriptManager control manages the communication between the client page and the server. It also manages the JavaScript files used at the client, takes care of partial-page updates. You can directly drag and drop this control on content page. It does not have a visual representation. It only used to manage AJAX processing. You cannot use more than one ScriptManager control on single web page.
< asp: ScriptManager ID="ScriptManager1" runat="server">

< /asp: ScriptManager>

ScriptManagerProxy Control

The ScriptManagerProxy control mainly used when we deals with Master Pages. The ScriptManagerProxy control can be used by content pages that use a master page. The Master page must have a ScriptManager control otherwise you will get error.

UpdatePanel Control

UpdatePanel control is the most important control in Microsoft’s server-side AJAX framework. The UpdatePanel control enables you to update a portion of a page without updating the entire page. With partial-page updates you can post portions of a page to the server and only receive updates to those portions. The UpdatePanel control is work as a container for other controls.

Example:

< asp:UpdatePanel ID="UpdatePanel1" runat="server">
< ContentTemplate>
< asp:Label ID="Label1" runat="server" Text="Label">
< asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
< /asp:Timer>
< /ContentTemplate>
< /asp:UpdatePanel>

protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToLocalTime().ToString();
}

Timer Control

The ASP.NET AJAX Timer control enables you to refresh an UpdatePanel in fixed time interval. The Timer control has one important property named Interval. You can specify the amount of time, in millisecond. The default value is 60,000 (1 minute).
The Timer control raises a Tick event automatically depending on the value of its Interval property.

UpdateProgress Control

The UpdateProgress control allows you to show to the user that work is being done and that they will get results soon. You can show the status of work done by using this control.

b) Tree view control.

Tree view web control is used to display the hierarchical data. User can bound the TreeView control with XML document to display the tree like structure. This control also works with SiteMapDataSource control for navigation purpose. Each node in the Tree is defined by key-value pair i.e. Text and Value properties of TreeNode. TreeNode elements also have NavigateUrl and Target properties for defining a hyperlink to navigate and a window or frame target.

< asp:TreeView ID="TreeView1" runat="server" >
< Nodes>
< asp:TreeNode Text="Country">
< asp:TreeNode Text="India" Value="ID-1234">
< asp:TreeNode Text="Maharashtra" Value="ID-1">

< /asp:TreeNode>
< asp:TreeNode Text="Kerala" Value="ID-2">

< /asp:TreeNode>
< asp:TreeNode Text="Rajasthan" Value="ID-3">

< /asp:TreeNode>
< /asp:TreeNode>
< asp:TreeNode Text="America" Value="ID-5678" />
< asp:TreeNode Text="Australia" Value="ID-910" />
< /asp:TreeNode>
< /Nodes>
< /asp:TreeView>

TreeView control supports the following important events.

- SelectedNodeChanged
- TreeNodeCheckChanged
- TreeNodeCollapsed
- TreeNodePopulate

Example:

This event will fire when you click on any node on the TreeView control.

protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
Response.Write(TreeView1.SelectedNode.Text);
}

c) Event Driven Programming.

It is an important feature of C# that is based upon delegate. An Event is a message or notification that is sent by an object such as control (Button, Checkbox, Radio button, etc.). After getting notification the program responds to by executing code. When an event is fired, all the registered method will be executed to handle the event. Events are members of a class and are declared using the event keyword. The general prototype of an event declaration

event event-delegate event-name;

Events always work with delegate. A delegate is an object that can refer to a method. It means that it can hold a reference to a method. The main advantage of a delegate is that it invokes the method at run time rather than compile time. Delegate in C# is similar to a function pointer in C/C++.

A delegate type is declared using the keyword delegate. The prototype of a delegate declaration is given below:

delegate ret-type name(parameter-list);

A delegate can call only those methods that have same signature and return type as delegate.



Example of an event:
using System;

namespace EventDemoApp
{
// A delegate type for an event.

delegate void DemoEventHandler();

// A class that contains an event.

class EventDemo
{
public event DemoEventHandler SomeEvent;

public void OnSomeEvent()
{
if (SomeEvent != null)
SomeEvent();
}
}
class Program
{
// An event handler.

static void Handler()
{
Console.WriteLine("Event occurred");
}
static void Main(string[] args)
{
EventDemo obj = new EventDemo();

obj.SomeEvent += Handler;

// Fire the event.
obj.OnSomeEvent();
}
}
}


 d) Any two client side state management technique

View state, control state, hidden fields, cookies, and query strings all stores the data on the client in various ways.

View State

The ViewState object provides a dictionary object for storing values between multiple requests for the same page. The page uses this method to preserve page and control property values between round trips.

Example:
//Writing to view state

ViewState.Add("MyVariable", "CarrerRide.com");

//Read from view state

String myData = (string) ViewState ["MyVariable"];
ViewState data available only within the same page not on the other page.

Cookie

A cookie is a small amount of data that server creates on the client. Cookies store a value in the user’s browser that the browser sends with every page request to the web server. When a web server creates a cookie, an additional HTTP header is sent to the browser when a page is served to the browser. The HTTP header looks like this:

Set-Cookie: message=Hello. After a cookie has been created on a browser, whenever the browser requests a page from the same application in the future, the browser sends a header that looks like this:

Cookie: message=Hello
Cookie is little bit of text information. You can store only string values when using a cookie. There are two types of cookies:

Session cookies: A session cookie exists only in memory. If a user closes the web browser, the session cookie delete permanently.

Persistent cookies: A persistent cookie, on the other hand, can available for months or even years. When you create a persistent cookie, the cookie is stored permanently by the user’s browser on the user’s computer

Creating cookie

protected void btnAdd_Click (object sender, EventArgs e)
{
Response.Cookies[“message”].Value = txtMsgCookie.Text;
}

// Here txtMsgCookie is the ID of TextBox.
// cookie names are case sensitive.

Reading Cookies

void Page_Load()
{
if (Request.Cookies[“message”] != null)
lblCookieValue.Text = Request.Cookies[“message”].Value;
}

// Here lblCookieValue is the ID of Label Control.

Disadvantage of cookies.
Cookie can store only string value.
Cookies are browser dependent.
Cookies are not secure.
Cookies can store small amount of data.

Query Strings

A query string is information that is appended to the end of a page URL. These values are visible to the user through his or her browser’s address bar. A typical query string might look like the following example:

http://www.CarrerRide.com/Mycompany.aspx?name=”ADT”

Do not rely on query strings to pass important or confidential data because it can be tampered with by a malicious user.

Example:

Response.Redirect("Empmaster.aspx?id=1");
string id = Request.QueryString["id"];
Post your comment

    Discussion

  • RE: Ajax controls, Tree view control, Event Driven Programming, client side state management technique -Roshan (11/23/15)
  • Please solve also any AIT paper
  • Advanced internet technology -Rakesh (09/16/15)
  • plz solved this questions ....
  • nov 2014 AIT paper -bhagat (05/07/15)
  • please solve the question for nov 2014 AIT paper.