Question : force asp.net web page to post back from another web page

I have a web application with 2 pages the first page has a data grid and the second detail page is use to add records to the dataset that populates the data grid.  From the data grid page, the detail page is called to add a new record.  What I am trying to do is after the detail record has been updated and the window closed I want the datagrid page to automatically post back to refresh the data in the grid to reflect the addition of the new record.  I had tried populating a textbox set with autopostback = true via a javascript (this script also closed the detail page) but the autopostback feature only executes with user input and tabing off the control.  Basically I am looking for a code snippet, or method that will do this.  I have seen similar applications in action but have found little reference as to how they perform.   I figure it will have to be a client side javascript which is not my strong point. Thanks, Tom Majarov

Answer : force asp.net web page to post back from another web page

Tom,
Try this out and let me know if it works for you.

/// GridPage.aspx ///
<%@ Page language="c#" Codebehind="GridPage.aspx.cs" AutoEventWireup="false" Inherits="Dev.GridPage" %>

 
   
 
 
   
     

     
      lblTimeLabel>

      Open Detail Page
   
 


/// GridPage.aspx.cs ///
using System;
using System.Web.UI.WebControls;

namespace Dev
{
  public class GridPage : System.Web.UI.Page
  {
    protected Label lblTime;
 
    private void Page_Load(object sender, System.EventArgs e)
    {
      lblTime.Text = DateTime.Now.ToLongTimeString();
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }

    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    private void InitializeComponent()
    {    
      this.Load += new System.EventHandler(this.Page_Load);
      this.ID = "GridPage";
    }
  #endregion
  }
}

/// DetailPage.aspx ///
<%@ Page language="c#" Codebehind="DetailPage.aspx.cs" AutoEventWireup="false" Inherits="Dev.DetailPage" %>

 
    Detail Page
 
 
   

     

      >Add Record
   

 


/// DetailPage.aspx.cs ///
using System;
using System.Web.UI.WebControls;

namespace Dev
{
  public class DetailPage : System.Web.UI.Page
  {
    protected LinkButton lnkAdd;

    private void Page_Load(object sender, System.EventArgs e)
    {
      // Put user code to initialize the page here
    }

    protected void lnkAdd_Command(object sender, CommandEventArgs e)
    {
      // Add record to Database ...

      RefreshDataGrid();
    }

    private void RefreshDataGrid()
    {
      string refreshScript =
        "\n";
      RegisterStartupScript("refreshScript", refreshScript);
    }

    #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
      //
      // CODEGEN: This call is required by the ASP.NET Web Form Designer.
      //
      InitializeComponent();
      base.OnInit(e);
    }
   
    ///
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    ///

    private void InitializeComponent()
    {    
      this.ID = "DetailPage";
      this.Load += new System.EventHandler(this.Page_Load);
    }
    #endregion
  }
}
Random Solutions  
 
programming4us programming4us