0% found this document useful (0 votes)
127 views6 pages

Practical 10 Working With Ajax and XML

This document describes code examples for using Ajax and XML in a web application. It includes examples of reading and writing XML files using XmlReader and XmlTextWriter. It also shows how to use various Ajax controls like UpdatePanel, UpdateProgress, and Timer to asynchronously update parts of a web page without reloading. The output demonstrates the date and time updating every 500 milliseconds within the UpdatePanel when the Timer ticks.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
127 views6 pages

Practical 10 Working With Ajax and XML

This document describes code examples for using Ajax and XML in a web application. It includes examples of reading and writing XML files using XmlReader and XmlTextWriter. It also shows how to use various Ajax controls like UpdatePanel, UpdateProgress, and Timer to asynchronously update parts of a web page without reloading. The output demonstrates the date and time updating every 500 milliseconds within the UpdatePanel when the Timer ticks.

Uploaded by

sushil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

T.Y.B.SC(I.T.

)-ADVANCED WEB PROGRAMMING-PAPER(III)


IT-7239
2018-2019

Practical 10
Working with Ajax and XML
A) Create a web application to demonstrate reading and writing operation
with XML.
Code-
10a.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="10a.aspx.cs" Inherits="_10a"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:Button ID="Button1" runat="server" Text="READ xml"
onclick="Button1_Click" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<br />
<br />
<asp:Button ID="Button2" runat="server" Text="WRITE xml"
onclick="Button2_Click" />
</div>
</form>
</body>
</html>

Design-

Page 1|6
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

10a.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
public partial class _10a : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
XmlReader red = XmlReader.Create(@"http://localhost:49361/prac10/XMLFile2.xml");
while (red.Read())
{
if (red.NodeType.Equals(XmlNodeType.Element))
{
string s = Label1.Text + " ";
Label1.Text = s + red.Name;
}
}
red.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{

XmlTextWriter textWriter = new XmlTextWriter("D:\\destination\\myXmFile.xml", null);


textWriter.WriteStartDocument();
textWriter.WriteStartElement("student");
textWriter.WriteStartElement("name", "");
textWriter.WriteString("Vicky");
textWriter.WriteEndElement();
textWriter.WriteStartElement("roll", "");
textWriter.WriteString("13");
textWriter.WriteEndElement();
textWriter.WriteEndDocument();
textWriter.Close();
}
}

XMLFile2.xml-
<?xml version="1.0" encoding="utf-8" ?>
<student>
Page 2|6
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

<name>Vicky</name>
<roll>13</roll>
</student>

Output-

After clicking on Read xml button-

After clicking on Write xml button-

After opening this file-

Page 3|6
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

C) Create a web application to demonstrate use of various Ajax controls.


Code-

10c.aspx-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="10c.aspx.cs" Inherits="_10c"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer runat="server" id="UpdateTimer" interval="500"
ontick="UpdateTimer_Tick" />
<asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
<ContentTemplate>
<asp:Label runat="server" id="DateStampLabel" />
</ContentTemplate>
</asp:UpdatePanel>
<br /><br />
<asp:UpdateProgress runat="server" id="PageUpdateProgress">
<ProgressTemplate>
Loading...
</ProgressTemplate>
</asp:UpdateProgress>
<asp:UpdatePanel runat="server" id="Panel">
<ContentTemplate>
Page 4|6
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

<asp:Button runat="server" id="UpdateButton" onclick="UpdateButton_Click"


text="Update" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>

Design-

10c.aspx.cs-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _10c : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
}
}

Output-
Page 5|6
T.Y.B.SC(I.T.)-ADVANCED WEB PROGRAMMING-PAPER(III)
IT-7239
2018-2019

After clicking on Update button-

Page 6|6

You might also like