Click here to Skip to main content
15,895,084 members
Articles / Web Development / XHTML

Partial update of parent page via AJAX (ASP.NET 2.0) on close of a child window - conditionally

Rate me:
Please Sign up or sign in to vote.
4.74/5 (52 votes)
23 Sep 2008CPOL3 min read 99.4K   1K   63  
Partial update of parent page based on a certain value passed from the child window via AJAX (using UpdatePanel).
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;

public partial class ParentForm : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Set default values to the control on PageLoad for first time.
            lblChildWinValue.Text = "ChildWin Value: " + "NONE";
            lblCurrTime.Text = "CurrTime: " + DateTime.Now.ToString();
            lblPageLoadTime.Text = "PageLoadTime: " + DateTime.Now.ToString();
        }        
    }
    protected void btnHiddenForUpdate_ServerClick(object sender, EventArgs e)
    {        
        //Update Panels update - repopulate the controls the way needed.
        lblChildWinValue.Text = "ChildWin Value: " + "SOME VALUE";
        lblCurrTime.Text = "CurrTime: " + DateTime.Now.ToString();
        lblChildWinValue.BackColor = Color.Yellow;
        lblCurrTime.BackColor = Color.Yellow;

        //Just to show that this label wont update as outside the update panel
        lblPageLoadTime.Text = "PageLoadTime: " + DateTime.Now.ToString();
        lblPageLoadTime.BackColor = Color.Yellow;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Intuit India
India India


A software professional for more than 17+ years building solutions for Web and Desktop applications.

Currently working at Intuit India.

Website: Learn By Insight
Github: Sandeep Mewara
LinkedIn: Sandeep Mewara

Strongly believe in learning and sharing knowledge.



Comments and Discussions