Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 14th, 2004, 03:05 PM
Authorized User
 
Join Date: Apr 2004
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)...

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

 
Old July 14th, 2004, 03:13 PM
Authorized User
 
Join Date: Apr 2004
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

 
Old July 15th, 2004, 11:52 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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.
 
Old July 15th, 2004, 12:01 PM
Authorized User
 
Join Date: Apr 2004
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.


 
Old July 15th, 2004, 12:03 PM
Authorized User
 
Join Date: Apr 2004
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..

 
Old July 19th, 2004, 08:57 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
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.





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.