473,473 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

VS2005: Events from User Control Stored in Session Do Not Fire

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);

}

}
}

Oct 23 '07 #1
2 2997
your approach is not valid. asp.net does not support this model. as the
controls can be disposed at form unload, they may be resurrected. most
are not writtn to support this. also if they keep any state of their
initialization, you are defeating it.

you should save the dataset in session not the controls.

-- bruce (sqlwork.com)
HammRadio wrote:
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);

}

}
}
Oct 24 '07 #2
Thanks bruce.

Any idea why Framework 1.1 kept the state and all events remained
valid? Was that jsut a "bug" in 1.1?

On Oct 23, 9:29 pm, bruce barker <nos...@nospam.comwrote:
your approach is not valid. asp.net does not support this model. as the
controls can be disposed at form unload, they may be resurrected. most
are not writtn to support this. also if they keep any state of their
initialization, you are defeating it.

you should save the dataset in session not the controls.

-- bruce (sqlwork.com)

HammRadio wrote:
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);
}
}
}- Hide quoted text -

- Show quoted text -

Oct 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kenton Smeltzer | last post by:
Hello All, I am having a problem with events and the addition of controls on a page I am developing. First let me tell you what I have tried and then maybe someone can see something I missed. ...
4
by: blue | last post by:
I have a drop-down list, a radio button list and a submit button. I'm adding these controls to a table and I'm adding the table to a Placeholder. I'm adding it to the Placeholder because I don't...
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
1
by: Alan Mendelevich | last post by:
Hi, I'm trying to render control stored in ascx file to a string. I succeed with the main part but events (at least OnLoad) doesn't fire (or aren't automatically wired to Page_Load() method in...
4
by: ryu | last post by:
I have a aspx page that loads a ascx file ie Web Control. My question is when does the postback of the web control occur? Is it when it is called via LoadControl? Or after the calling page's...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
6
by: Steve Hershoff | last post by:
Hi everyone, I've got a strange one here. There are two datagrids on my page, one nested within the other. I'll refer to them as the topmost and secondary datagrids. In the topmost...
8
by: MrNobody | last post by:
If I have a control like say a drop down list and I have some kind of onSelectItem change event, is there a way to temporarily suspend the event handling (without removing the event and then...
5
by: studio60podcast | last post by:
I have been fighting with this for almost two days and I can't figure it out. I'm hoping someone can shed some light on my problem. I have a web user control (NewAccountHolders) that contains a...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.