Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2004, 03:05 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Page Load event

Hi,

I have this weird problem. In one of the applications that I am developing the page load event is being fired twice. First when the page is loading and then at unloading. This is causing me a lot of trouble. The code for one of the pages is given below. Does anyone have any ideas about why this is happenning?

Thanks in advance.
Qadeer.

Code
-----------------------------------------------------------------
public class Step1 : System.Web.UI.Page
    {
        protected System.Web.UI.WebControls.Label lbl1;
        protected System.Web.UI.WebControls.TextBox txt1;
        protected System.Web.UI.WebControls.CheckBox checkbox1;
        protected System.Web.UI.WebControls.Label lbl2;
        protected System.Web.UI.WebControls.TextBox txt2;
        protected System.Web.UI.WebControls.Button btn2;
        protected System.Web.UI.WebControls.CheckBox checkbox2;

        #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()
        {
            this.btn2.Click += new System.EventHandler(this.btn2_Click);
            this.Unload += new System.EventHandler(this.Page_Unload);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

private void Page_Load(object sender, System.EventArgs e)...
private void Page_Unload(object sender, System.EventArgs e)...
private void btn2_Click(object sender, System.EventArgs e)...

----------------------------------------------------------------

  #2 (permalink)  
Old July 14th, 2004, 03:13 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am trying to debug the code and I just found out that the OnInit(e) method mentioned in the above code is being called twice (on page load and on page unload). Does anyone know how the oninit() method gets fired?

Thanks,
Qadeer

  #3 (permalink)  
Old July 15th, 2004, 11:52 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

onInit is fired by ASP.NET runtime. But that shouldn't result in page_load being called once at each end of the page. That is very strange.
  #4 (permalink)  
Old July 15th, 2004, 12:01 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Is this happenning due to postback since I am redirecting to a diffent page using the button click event?

Also here is something else that I noticed and I don't quite understand why this is happennig. I have a method Page_Unload() that is being executed when Unloading the page. In Visual Studio while debugging if I click on the code inside this method and click on "Run to Cursor" the program execution stops even before the page is unloaded. I have absolutely no idea why this is happenning.


  #5 (permalink)  
Old July 15th, 2004, 12:03 PM
Authorized User
 
Join Date: Apr 2004
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

CORRECTION IN THE ABOVE POST:

Also here is something else that I noticed and I don't quite understand why this is happennig. I have a method Page_Unload() that is being executed when Unloading the page. In Visual Studio while debugging if I click on the code inside this method and click on "Run to Cursor" the program execution stops even before the page is LOADED. I have absolutely no idea why this is happenning.

sorry about that..

  #6 (permalink)  
Old July 19th, 2004, 08:57 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Surely, if you redirect to another page, that page's OnInit will run.

I have seen some oddities with Visual Studio while debugging.
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
flash button not causing page load event olambe Flash (all versions) 3 June 22nd, 2007 10:17 PM
Load external script within Page_Load Event kwilliams General .NET 0 October 9th, 2006 10:56 AM
Strange problem in page load event software_developer_kk ASP.NET 1.0 and 1.1 Professional 1 September 13th, 2005 12:51 PM
flash button not causing page load event olambe BOOK: ASP.NET Website Programming Problem-Design-Solution 1 June 27th, 2004 09:02 PM
Page Base Load event order frayed_edge BOOK: ASP.NET Website Programming Problem-Design-Solution 3 March 4th, 2004 08:37 AM



All times are GMT -4. The time now is 01:02 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.