473,888 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
+ 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.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Sandbox
{
public partial class ucUserControlTe st : System.Web.UI.U serControl
{

protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}

protected void Page_Load(objec t sender, EventArgs e)
{

if (!IsPostBack)
{
this.TextBox1.T ext = "Page is Loaded!";
}
}

private void InitializeCompo nent()
{
this.cmdSave.Cl ick += new
EventHandler(th is.cmdSave_Clic k);

}

public void cmdSave_Click(o bject sender, EventArgs e)
{

this.TextBox1.T ext = "I Clicked Save.";

}
}
}
Here is the form:

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Sandbox
{
public partial class UserControlTest Form : System.Web.UI.P age
{

protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}

private void InitializeCompo nent()
{
if (!IsPostBack)
{
LoadUserControl s();
}
else
{
LoadSessionCont rol();

}
}

protected void Page_Load(objec t sender, EventArgs e)
{
/// Nothing Happens Here

}
private void LoadUserControl s()
{

UserControl temp = (UserControl)
LoadControl("uc UserControlTest .ascx");
this.pForm.Cont rols.Add(temp);
Session.Add("Cu rrentFormContro l", temp);
}

private void LoadSessionCont rol()
{

UserControl temp = (UserControl)
Session["CurrentFormCon trol"];
/// Clears any Controls on Page. Behavior is the same
whether this is here or not.
this.pForm.Cont rols.Clear();
this.pForm.Cont rols.Add(temp);

}

}
}

Oct 23 '07 #1
2 3022
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.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Sandbox
{
public partial class ucUserControlTe st : System.Web.UI.U serControl
{

protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}

protected void Page_Load(objec t sender, EventArgs e)
{

if (!IsPostBack)
{
this.TextBox1.T ext = "Page is Loaded!";
}
}

private void InitializeCompo nent()
{
this.cmdSave.Cl ick += new
EventHandler(th is.cmdSave_Clic k);

}

public void cmdSave_Click(o bject sender, EventArgs e)
{

this.TextBox1.T ext = "I Clicked Save.";

}
}
}
Here is the form:

using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;

namespace Sandbox
{
public partial class UserControlTest Form : System.Web.UI.P age
{

protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}

private void InitializeCompo nent()
{
if (!IsPostBack)
{
LoadUserControl s();
}
else
{
LoadSessionCont rol();

}
}

protected void Page_Load(objec t sender, EventArgs e)
{
/// Nothing Happens Here

}
private void LoadUserControl s()
{

UserControl temp = (UserControl)
LoadControl("uc UserControlTest .ascx");
this.pForm.Cont rols.Add(temp);
Session.Add("Cu rrentFormContro l", temp);
}

private void LoadSessionCont rol()
{

UserControl temp = (UserControl)
Session["CurrentFormCon trol"];
/// Clears any Controls on Page. Behavior is the same
whether this is here or not.
this.pForm.Cont rols.Clear();
this.pForm.Cont rols.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.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
namespace Sandbox
{
public partial class ucUserControlTe st : System.Web.UI.U serControl
{
protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}
protected void Page_Load(objec t sender, EventArgs e)
{
if (!IsPostBack)
{
this.TextBox1.T ext = "Page is Loaded!";
}
}
private void InitializeCompo nent()
{
this.cmdSave.Cl ick += new
EventHandler(th is.cmdSave_Clic k);
}
public void cmdSave_Click(o bject sender, EventArgs e)
{
this.TextBox1.T ext = "I Clicked Save.";
}
}
}
Here is the form:
using System;
using System.Data;
using System.Configur ation;
using System.Collecti ons;
using System.Web;
using System.Web.Secu rity;
using System.Web.UI;
using System.Web.UI.W ebControls;
using System.Web.UI.W ebControls.WebP arts;
using System.Web.UI.H tmlControls;
namespace Sandbox
{
public partial class UserControlTest Form : System.Web.UI.P age
{
protected override void OnInit(EventArg s e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form
Designer.
//
InitializeCompo nent();
}
private void InitializeCompo nent()
{
if (!IsPostBack)
{
LoadUserControl s();
}
else
{
LoadSessionCont rol();
}
}
protected void Page_Load(objec t sender, EventArgs e)
{
/// Nothing Happens Here
}
private void LoadUserControl s()
{
UserControl temp = (UserControl)
LoadControl("uc UserControlTest .ascx");
this.pForm.Cont rols.Add(temp);
Session.Add("Cu rrentFormContro l", temp);
}
private void LoadSessionCont rol()
{
UserControl temp = (UserControl)
Session["CurrentFormCon trol"];
/// Clears any Controls on Page. Behavior is the same
whether this is here or not.
this.pForm.Cont rols.Clear();
this.pForm.Cont rols.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
2437
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. First I tried adding the controls and the event handlers for my control in the Initialize Components method of my page in the hopes that it would fire the event before the
4
2568
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 know exactly where the table will be located on the page until runtime. Before the form control table is added to the Placeholder, I'm adding a whole bunch of tables to the Placeholder. This is a flowchart program and I have multiple action boxes...
1
7597
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
5129
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 the control). Here's what I do (simplified): in a script that renders to a string: -------
4
1574
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 postback or is it random?
6
3387
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 the usual stuff of recreating the usercontrol in the Page Init event. The 'failure' sequence is as follows: - select web form button to display the user control - select user control button, event fires - select web form button to display...
6
1766
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 datagrid's OnItemDataBound() method we check for the row in which it's appropriate to add the secondary datagrid. Exactly one row in the topmost grid will contain the secondary grid.
8
2007
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 re-attaching it?) while I edit it's contents which would otherwise cause the event to fire? Or is there maybe a way in my event handler to tell if the user triggered it as opposed to the program itself?
5
1606
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 generic list of another web user control (NewAccountHolder). I place NewAccountHolders in a page and all renders properly, but the _lnkRemove_Click never fires when I click "Remove". If I create instances of NewAccountHolder outside of...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10778
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10439
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7990
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5819
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
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 we have to send another system
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.