H
HammRadio
I am exploring converting my web app (current Framework 1.1) to
Framework 2.0. Everything went smoothly save for one item. To reduce
the trips to the database, when loading user controls (like a large
datagrid or form), we store the grid or form in Session Object. On
PostBack we grab the control from the session, add it to our main
form. In VS 2003 (1.1), the page will fire any event called in the
custom control, e.g, cmdSave_Click. In VS 2005 (2.0), the control is
loaded, but no event occurs.
In VS 2003
Page Init -> Load UserControl -> cmdSave -> Click -> PostBack -> Page
Init -> Load Control From Session -> Page Load -> cmdSave_Click fires
In VS 2003
Page Init -> Load UserControl -> cmdSave -> Click -> PostBack -> Page
Init -> Load Control From Session -> Page Load -> cmdSave_Click does
not fire.
Any thoughts on why one would work in 2003 and one wouldn't work in
2005.
I thought it might be just my code. So I created a whole new
application that simplifies everything, here is the user control:
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;
namespace Sandbox
{
public partial class ucUserControlTest : System.Web.UI.UserControl
{
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Text = "Page is Loaded!";
}
}
private void InitializeComponent()
{
this.cmdSave.Click += new
EventHandler(this.cmdSave_Click);
}
public void cmdSave_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "I Clicked Save.";
}
}
}
Here is the form:
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;
namespace Sandbox
{
public partial class UserControlTestForm : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
}
private void InitializeComponent()
{
if (!IsPostBack)
{
LoadUserControls();
}
else
{
LoadSessionControl();
}
}
protected void Page_Load(object sender, EventArgs e)
{
/// Nothing Happens Here
}
private void LoadUserControls()
{
UserControl temp = (UserControl)
LoadControl("ucUserControlTest.ascx");
this.pForm.Controls.Add(temp);
Session.Add("CurrentFormControl", temp);
}
private void LoadSessionControl()
{
UserControl temp = (UserControl)
Session["CurrentFormControl"];
/// Clears any Controls on Page. Behavior is the same
whether this is here or not.
this.pForm.Controls.Clear();
this.pForm.Controls.Add(temp);
}
}
}
Framework 2.0. Everything went smoothly save for one item. To reduce
the trips to the database, when loading user controls (like a large
datagrid or form), we store the grid or form in Session Object. On
PostBack we grab the control from the session, add it to our main
form. In VS 2003 (1.1), the page will fire any event called in the
custom control, e.g, cmdSave_Click. In VS 2005 (2.0), the control is
loaded, but no event occurs.
In VS 2003
Page Init -> Load UserControl -> cmdSave -> Click -> PostBack -> Page
Init -> Load Control From Session -> Page Load -> cmdSave_Click fires
In VS 2003
Page Init -> Load UserControl -> cmdSave -> Click -> PostBack -> Page
Init -> Load Control From Session -> Page Load -> cmdSave_Click does
not fire.
Any thoughts on why one would work in 2003 and one wouldn't work in
2005.
I thought it might be just my code. So I created a whole new
application that simplifies everything, here is the user control:
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;
namespace Sandbox
{
public partial class ucUserControlTest : System.Web.UI.UserControl
{
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.Text = "Page is Loaded!";
}
}
private void InitializeComponent()
{
this.cmdSave.Click += new
EventHandler(this.cmdSave_Click);
}
public void cmdSave_Click(object sender, EventArgs e)
{
this.TextBox1.Text = "I Clicked Save.";
}
}
}
Here is the form:
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;
namespace Sandbox
{
public partial class UserControlTestForm : System.Web.UI.Page
{
protected override void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeComponent();
}
private void InitializeComponent()
{
if (!IsPostBack)
{
LoadUserControls();
}
else
{
LoadSessionControl();
}
}
protected void Page_Load(object sender, EventArgs e)
{
/// Nothing Happens Here
}
private void LoadUserControls()
{
UserControl temp = (UserControl)
LoadControl("ucUserControlTest.ascx");
this.pForm.Controls.Add(temp);
Session.Add("CurrentFormControl", temp);
}
private void LoadSessionControl()
{
UserControl temp = (UserControl)
Session["CurrentFormControl"];
/// Clears any Controls on Page. Behavior is the same
whether this is here or not.
this.pForm.Controls.Clear();
this.pForm.Controls.Add(temp);
}
}
}