Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

wrong event handler called

Posted on 2003-11-21
15
Medium Priority
?
425 Views
Last Modified: 2012-05-04
I place user controls B,C,D in user control A. I place A in some.aspx.

After I clicked B, C or D's event handler will not be called when clicked. If I click C or D after I click B, I'll just see the results I got from clicking B. However, if I click C or D then click X, it would work. In other words, the moment I click on B, every other event handler will not be reachable anymore.

How do I debug this? Where should I place the break points? Who calls the OnInit() in each user control? I want to know why when C or D is clicked, the B handler is called.

I see that something called OnInit() of BCD then OnInit() of A, onInit() of "some.aspx", then page_load in the oposite direction. However, I don't know how I can set the break point so that I can see why B handler is being called when not supposed to.

Thanks.
0
Comment
Question by:samliam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
15 Comments
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9803028
May be we can understand you better when you post some original code instead of talking about A, B, C, D, Y and Z. Often the problem is somewhere else where it's not expected.
0
 

Author Comment

by:samliam
ID: 9804078
Original code is too long to post here. So I'll post the user control that "dominates" the other user controls: (i.e., when this control is clicked, other controls are not reachable anymore. In other words, if I click the other controls, the program will call this controls handler!)

private void Page_Load(object sender, System.EventArgs e)
{
   if(!IsPostBack)
    {                  
        dropdown.DataSource=.....;
        dropdown.DataBind();
    }
}

#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.
/// </summary>
private void InitializeComponent()
{
    this.dropdown.SelectedIndexChanged += new   System.EventHandler(this.dropdown_SelectedIndexChanged);
    this.Load += new System.EventHandler(this.Page_Load);
}
#endregion

private void dropdown_SelectedIndexChanged(object sender, System.EventArgs e)
{
    String url=ConfigurationSettings.AppSettings["baseURL"];
    String maker=dropdown.SelectedItem.ToString();
    url+="some.aspx?dropdn=";
    url+=maker;
    Response.Redirect(url);                  
}
0
 

Author Comment

by:samliam
ID: 9804139
How would you set the break points?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 10

Expert Comment

by:ptmcomp
ID: 9804220
I think the code here is fine. Did you name the control instances same as the CustomControl's name? Are these A, B, C and D from same type? I think to help you I would need the whole project.
0
 

Author Comment

by:samliam
ID: 9804284
Can you tell me first how you would debug this?
0
 

Author Comment

by:samliam
ID: 9805510
OK. Do you know the answer to the following problem?

I added a statement "Response.Write("Blah..");" and commented out later.

I do Build->Clean Solution, rebuild. I still see "Blah.."  I do not do any caching. Where is this "Blah.." from? How do I get rid of it?
0
 

Author Comment

by:samliam
ID: 9805524
The page must have been cached by the IE6 browser? I have the internet option -> check for new version of stored pages: "automatically". Doesn't this turn off caching?
0
 

Author Comment

by:samliam
ID: 9805541
I have simplified the problem as follows.

I create a userControl which contains a dropwdown list (set autoPostBack to 'true'). The event handler of the dropdown list has only 1 line:

Response.Redirect("http://site1");

I create another useControl containing a button. The event handler has this line:

Response.Redirect("http://site2");

I drag and drop the 2 user controls into a .aspx webform and run it. The button control is not reachable after I click the dropdown control. (in other words, after I go to site1, I cannot go to site2.)


0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9805619
Do both (site1.aspx and site2.aspx) have these user controls? I mean after you choose something from the dropdown your not anmyore on the same aspx, are you?
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9805620
Place something like MyLabel.Text = "event 1 fired" instead of the redirect and check if it works.
0
 

Author Comment

by:samliam
ID: 9806185
It's simply:
Response.Redirect("http://www.yahoo.com");

I added a label and
label.Text="...";
same thing.
0
 
LVL 10

Expert Comment

by:ptmcomp
ID: 9806323
Open the page, save the html, press the button and save the html again and compare them (e.g. with SourceSafe)
0
 

Author Comment

by:samliam
ID: 9806469
The only differences is ViewState and the label text (from "Label"  to "Button Clicked!").
0
 

Author Comment

by:samliam
ID: 9807257
are you able to reproduce the problem with your VS.NET?
0
 
LVL 28

Accepted Solution

by:
mmarinov earned 200 total points
ID: 9839751
samliam,

as you ask me - this is not an .net bug :-(
the problem is that every time the page is submit ( ispostback = true ) asp_net initialize every user control on your page.

You can set some conditions by which the asp_net will execute the code in page_load or not

If you want to debug the project by adding break point - just add them at the beginning of every page_load of user controls and see why after clicking B nothing else is working

B..G
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question