?
Solved

500pts: AutoEventFireup launches PAGE_LOAD twice with some of my pages, why?

Posted on 2006-05-29
7
Medium Priority
?
397 Views
Last Modified: 2012-05-05
Hi there

Can anyone help?

I have been having a problem with some pages that i imported into visual studio 2005 from vs 2003....

They were running page_load twice but i did manage fix it ... i set the AutoEventFireUp to false... and it works...

Page_load now launches once... So i thought i would ensure a new page that i create also works and fires the Page_Load event...

So i set a new page to false BUT now page_load never fires... Which i believe is the way it is supposed to work.

So my question is... why do my imported pages still fire the events when set to autoEventFireup false....

I can't see any real major differences that would cause this although i have spotted this method..

override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }

but i did comment out the code and the imported page with autoeventfireup set to false still fires ...

Can anyone help..... I want the imported pages to work the same as a new one....

I can put up the source.. It isn't big, one of them is an error page so it isn't big..

I checked this in the page and currently it contains this

<%@ Page language="c#" Codebehind="error.aspx.cs" AutoEventWireup="False" Inherits="IGAPP.error" %>

hence the it uses codebehind rather than codefile - although I did try changing it to codefile.... i got an error

Thanks in advance for any help.

Ian
0
Comment
Question by:ianinspain
  • 3
  • 3
7 Comments
 
LVL 19

Assisted Solution

by:DreamMaster
DreamMaster earned 750 total points
ID: 16783553
Hi Ian,

If you do set AutoEventWireup to true, Visual Studio will generate code to bind the events and the page framework will automatically call events based on their names. This can result in the same event code being called twice when the page runs.

Regards,
Max.
0
 

Author Comment

by:ianinspain
ID: 16783628
Yes thats what i was reading  BUT i created a brand new page ... and i set it to false and set a break point in my page_load event and it never fires but the old pages have been set to false and they still fire

In my code i don't see anything that would cause this... here is the code from an imported page that is still firing the page_load event .... thank god only once....

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace TTOTOOLS
{
      /// <summary>
      /// Esta es la página que se muestra cuando no se ha mostrado la informacion o cuando ha habido un error.
      /// </summary>
      public partial class error : System.Web.UI.Page
      {
            /// <summary>
            /// Panel para ocultar la tabla con el mensaje en caso de que sea un error no controlado.
            /// </summary>
            protected System.Web.UI.WebControls.Panel PanelDesc;
            /// <summary>
            /// Label en el que se mostrará el código de error y su descripción.
            /// </summary>
            protected System.Web.UI.WebControls.Label lblError;
      
            protected void Page_Load(object sender, System.EventArgs e)
            {
                  // Recojo los datos de la página en la que se ha producido el error.
                  string      strErrorCode            = Context.Items[ "error_code" ].ToString();
                  string      strErrorDesc            = Context.Items[ "error_description" ].ToString();
                  string      strErrorPage            = Context.Items[ "error_page" ].ToString();
                  string      strMensaje                  = "";
           
                  // Muestro el error en la página.
                  if( strErrorCode != "-1" && strErrorCode != "" )
                  {
                        // Construcción del mensaje a mostrar.
                        strMensaje = "Código de error: " + strErrorCode + "<br>";
                        strMensaje += "Descripción: " + strErrorDesc;
                        this.lblError.Text = strMensaje;

                        // Pongo visible el Panel que contiene el mensaje.
                        this.PanelDesc.Visible = true;
                  }
                  else
                  {
                        // Ha habido un error no controlado. Lo guardo un log.
                        FileStream                        fs = new FileStream( Server.MapPath( "" ) + "\\logit.log", System.IO.FileMode.Append );
                        StreamWriter                  sw = new StreamWriter( fs, System.Text.Encoding.Default );

                        string strLine = DateTime.Now.ToString() + "|" + strIdUser + "|" + strErrorPage + "|" + Request.QueryString + "|" + strErrorCode + "|" +
                              ((strErrorDesc.IndexOf("text/html") == -1) ?strErrorDesc :"WebServices: Servidor no disponible, Error en tiempo de ejecución, Unable to process request, ...");



                        try
                        {
                    sw.WriteLine(Server.HtmlDecode(strLine));
                    sw.Flush();
                        }
                        catch{}

                        sw.Close();
                        fs.Close();
                  }

                  Context.Items.Clear();
            }

            #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);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    

            }
            #endregion
      }
}
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 16783635
I'm pretty sure this has to do with the code that is created by Visual Studio when it was set to true before.

I will look closer at your code at a later time, bit too busy right now..

Regards,
Max.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ianinspain
ID: 16783647
Great thanks... Max...

Ian
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 750 total points
ID: 16788045
>>Yes thats what i was reading  BUT i created a brand new page ... and i set it to false and set a break point in my page_load event and it never fires .. so u will need a line of code like
this.Load += new System.EventHandler(this.Page_Load);
to link the event to the method ..
here the events are not automatically linked and so the event is never fired

>>but the old pages have been set to false and they still fire
the linking of event handler with the methods might already be present .. so its getting fired .. if u set it AutoEventWireup to true now, the automatic link also happens and the load gets fired twice ..

don't u have this line anywhere in ur code
this.Load += new System.EventHandler(this.Page_Load);

Rejo
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 16788060
Exactly what I meant to say Rejojohny, and did say...just without so many words.. ;)

Sorry I didn't look at your code anymore yesterday Ian, I got the news that I became an uncle...somehow that was quite distracting ;)

Regards,
Max.
0
 

Author Comment

by:ianinspain
ID: 16798495
Thanks for everyone's help... I will split points as both answers helped me to find the problem...

Here is the solution..

In the aspx page there is a page directive that is called "Codebehind", if you leave it like this and leave autoeventwireup to true .. Page_load runs twice... so you have to set to "false" for it to load once..

New pages don't use directive "codebehind" ... they use codefile...

So if i edit them to use "codefile" then everything function as it should i..e false doesn't run ... and true ones once...

Regards

Ian
0

Featured Post

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.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

829 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