bigd2001grad
asked on
Controls on my .ascx control become unbound from events
I can't seem to consistently reproduce this error, but whenever I edit the UI of an .ascx control and toggle to the code behind to make changes - some of my controls become "unbound" from their click events. So, whenever I debug the web application, the controls (buttons) don't do anything when clicked. This happens infrequently, but it is a pain to have to go back, create new click events and copy the code over from the inactive events to the new ones.
Some background:
Visual Studio 2003 Enterprise Architect
Language: ASP.NET 1.1, C# codebehind
Database: SQL Server 2000
Proficiency: Moderate - Advanced
This has happened to several members of my programming team and I've come across the issue before with other clients.
I appreciate the help and look forward to your feedback.
Some background:
Visual Studio 2003 Enterprise Architect
Language: ASP.NET 1.1, C# codebehind
Database: SQL Server 2000
Proficiency: Moderate - Advanced
This has happened to several members of my programming team and I've come across the issue before with other clients.
I appreciate the help and look forward to your feedback.
Its getting reloaded each time you leave,, just like a web page...
are all the objects being disposed and re initiated properly?
try a custom click event? in the codebehind
are all the objects being disposed and re initiated properly?
try a custom click event? in the codebehind
ASKER
They are all be handled properly.
Actually, it's the custom click events we usually have the problem with. It is for this reason we don't put custom click events in InitializeComponent(). Below is a clipping of where we were having some of our problems.
override protected void OnInit(EventArgs e)
{
InitializeComponent();
///we'd usually call a method that contained all of our custom click events here
base.OnInit(e);
}
private void InitializeComponent()
{
this.ddlEdc.SelectedIndexC hanged += new System.EventHandler(this.d dlEdc_Sele ctedIndexC hanged);
this.btnDeleteIdrUsageDeta il.Click += new EventHandler(btnDeleteIdrU sageDetail _Click);
this.btnViewUsage.Click += new System.EventHandler(this.b tnViewUsag e_Click);
this.btnViewNormalizedUsag e.Click += new System.EventHandler(this.b tnViewNorm alizedUsag e_Click);
this.btnSavePremise.Click += new System.EventHandler(this.b tnSavePrem ise_Click) ;
this.btnCancel.Click += new System.EventHandler(this.b tnCancel_C lick);
this.grdMonthlyUsageDetail .UpdateCom mand += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.grdMont hlyUsageDe tail_Updat eCommand);
this.grdMonthlyUsageDetail .CancelCom mand += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.grdMont hlyUsageDe tail_Cance lCommand);
this.grdMonthlyUsageDetail .EditComma nd += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.grdMont hlyUsageDe tail_EditC ommand);
this.grdMonthlyUsageDetail .DeleteCom mand += new System.Web.UI.WebControls. DataGridCo mmandEvent Handler(th is.grdMont hlyUsageDe tail_Delet eCommand);
this.Load += new System.EventHandler(this.P age_Load);
}
Actually, it's the custom click events we usually have the problem with. It is for this reason we don't put custom click events in InitializeComponent(). Below is a clipping of where we were having some of our problems.
override protected void OnInit(EventArgs e)
{
InitializeComponent();
///we'd usually call a method that contained all of our custom click events here
base.OnInit(e);
}
private void InitializeComponent()
{
this.ddlEdc.SelectedIndexC
this.btnDeleteIdrUsageDeta
this.btnViewUsage.Click += new System.EventHandler(this.b
this.btnViewNormalizedUsag
this.btnSavePremise.Click += new System.EventHandler(this.b
this.btnCancel.Click += new System.EventHandler(this.b
this.grdMonthlyUsageDetail
this.grdMonthlyUsageDetail
this.grdMonthlyUsageDetail
this.grdMonthlyUsageDetail
this.Load += new System.EventHandler(this.P
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
One way would be to test in the page load if an object exists then fine,, if nothing then it surely passed OnInit. Maybe an error is not being caught,,, setup a try block
ASKER
I attempted the catch block and no errors were thrown. As for the init - I created a new one, tried some custom events and everything worked fine. I haven't been able to consistently get my error to re-occur.
Could this be more of a visual studio bug than a programming flaw?
Could this be more of a visual studio bug than a programming flaw?
It could be,
But the fact remains, if your InitializeComponent is not being called or some how not initializing the Event Handlers do to some kind of error it can be attributed to only a few things.
i can think of;
Your losing state in iis? bin being unloaded?
Error not being caught.
the parent form is not initializing the control? < Maybe a good place to look!
what if you created the control in code “dim something as your control” or be sure the control has been instantiated?.
But the fact remains, if your InitializeComponent is not being called or some how not initializing the Event Handlers do to some kind of error it can be attributed to only a few things.
i can think of;
Your losing state in iis? bin being unloaded?
Error not being caught.
the parent form is not initializing the control? < Maybe a good place to look!
what if you created the control in code “dim something as your control” or be sure the control has been instantiated?.
ASKER
After a little research...
InitializeComponent is being called, it is only the event handlers that are being "unwired". In some cases it is because a user double clicks on a control and instead of being taken to the existing click event method, a new one is created and the pre-existing method is ignored in the background. What confuses me is when event handlers and controls aren't touched, a new event handler is not written but the event handlers still become unwired. Because ReSharper identifies the disconnected nature of the event handlers before I even compile, I can rule out IIS having anything to do with it.
Does that help clarify a little?
InitializeComponent is being called, it is only the event handlers that are being "unwired". In some cases it is because a user double clicks on a control and instead of being taken to the existing click event method, a new one is created and the pre-existing method is ignored in the background. What confuses me is when event handlers and controls aren't touched, a new event handler is not written but the event handlers still become unwired. Because ReSharper identifies the disconnected nature of the event handlers before I even compile, I can rule out IIS having anything to do with it.
Does that help clarify a little?
ASKER
I contacted Microsoft about the issue and apparently there is a bug in VS 2003 that disconnects a function/event from its object while doing heavy lifting in the background. The issue was resolved in VS 2005.
Thank you 5thcav for pointing me in the right direction.
Thank you 5thcav for pointing me in the right direction.
ASKER
- just thought I'd throw that in there...