Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PRACTICAL -16

AJAX

Webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="AJAX.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:Label ID="lblmsg" runat="server" Text="Score of cricketer with
max_id:"></asp:Label>
<asp:Label ID="lblrun" runat="server" Text="Label"></asp:Label>
<asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Interval="1000"></asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>

</div>
</form>
</body>
</html>

Webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AJAX
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Timer1_Tick(object sender, EventArgs e)


{
try
{
SqlConnection con = new SqlConnection("Data Source=(LocalDB)\\
MSSQLLocalDB;AttachDbFilename=C:\\Users\\Admin\\source\\repos\\AJAX\\AJAX\\App_Data\\
Database1.mdf;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "select max(match_id) from match";
int i;
i = Convert.ToInt32(cmd.ExecuteScalar());
cmd.CommandText = "select score from match where match_id=" + i;
SqlDataReader ad;
ad = cmd.ExecuteReader();
ad.Read();
lblrun.Text = ad[0].ToString();
con.Close();

}
catch (Exception ex)
{
lblmsg.Text = ex.ToString();
}
}
}
}

Output:

You might also like