For using simple update panel in asp.net first need add the Script Manager, after that add the Update Panel control and add the <ContentTemplate> </ContentTemplate>, <Triggers>, </Triggers> tags.
- Inside the Content template please add the list of controls.
- Inside the Triggers add asp:AsyncPostBackTrigger for the event capture for the which controls event need to use the update panel.
The following codes are easy understand the AJAX Update panel control
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
The C# code behide is looks like :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
// Working with Ajax Update Panel
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
lblAge.Visible = false;
}
// When the txtDOB text change event fired we need to calculate the
//Age of the Give Person and display Age in Years with Days
protected void txtDOB_TextChanged(object sender, EventArgs e)
{
// TimeSpan class is used to find the time differnece and stored result temp
TimeSpan tsp=TimeSpan.MinValue;
try
{
DateTime dtDOB = Convert.ToDateTime(txtDOB.Text.Trim());
tsp = DateTime.Now - dtDOB;
}
catch (Exception ex)
{
lblAge.Visible = true;
lblAge.Text=ex.Message.Trim();
}
lblAge.Visible = true;
lblAge.Text = "Hi Mr/Ms." + TextBox1.Text.Trim() + ",
Your AGE:" + (tsp.Days / 365).ToString() + " Years " + (tsp.Days % 365).ToString() + " Days";
}
}



0 comments:
Post a Comment