Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Back Room
  4. C# Can be so stupid sometimes...

C# Can be so stupid sometimes...

Scheduled Pinned Locked Moved The Back Room
csharpasp-netvisual-studiodesignquestion
9 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nick Parker
    wrote on last edited by
    #1

    I have been working on creating a forum in C# for ASP.NET recently. I would just like to point out something that doesn't make any sense. Inside the constructor we a whole bunch of extra calls if you use an IDE, why when it's not needed?

    using System;
    using System.Collections;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO;

    namespace DeveloperNotesForum
    {
    public class Forum:System.Web.UI.Page
    {

    	//Constructor
    	public Forum()
    	{
    		Page.Init += new System.EventHandler(Page\_Init);	
    	}
    	
    	private void Page\_Init(object sender, EventArgs e)
    	{
    		InitializeComponent();	
    	}
    	
    	private void InitializeComponent()
    	{
    		this.Load += new System.EventHandler(this.Page\_Load);	
    	}
    	
    	private void Page\_Load(object sender, EventArgs e)
    	{
    		Response.Write("Hello");	
    	}		
    			
    	
    	
    }
    

    }

    But you only have to do this:

    using System;
    using System.Collections;
    using System.Data;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.IO;

    namespace DeveloperNotesForum
    {
    public class Forum:System.Web.UI.Page
    {

    	//Constructor
    	public Forum()
    	{
    		this.Load += new System.EventHandler(this.Page\_Load);	
    	}
    	
    	
    	private void Page\_Load(object sender, EventArgs e)
    	{
    		Response.Write("Hello");	
    	}		
    			
    	
    	
    }
    

    }

    Nick Parker
    **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


    **

    P J P R 4 Replies Last reply
    0
    • N Nick Parker

      I have been working on creating a forum in C# for ASP.NET recently. I would just like to point out something that doesn't make any sense. Inside the constructor we a whole bunch of extra calls if you use an IDE, why when it's not needed?

      using System;
      using System.Collections;
      using System.Data;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.HtmlControls;
      using System.IO;

      namespace DeveloperNotesForum
      {
      public class Forum:System.Web.UI.Page
      {

      	//Constructor
      	public Forum()
      	{
      		Page.Init += new System.EventHandler(Page\_Init);	
      	}
      	
      	private void Page\_Init(object sender, EventArgs e)
      	{
      		InitializeComponent();	
      	}
      	
      	private void InitializeComponent()
      	{
      		this.Load += new System.EventHandler(this.Page\_Load);	
      	}
      	
      	private void Page\_Load(object sender, EventArgs e)
      	{
      		Response.Write("Hello");	
      	}		
      			
      	
      	
      }
      

      }

      But you only have to do this:

      using System;
      using System.Collections;
      using System.Data;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;
      using System.Web.UI.HtmlControls;
      using System.IO;

      namespace DeveloperNotesForum
      {
      public class Forum:System.Web.UI.Page
      {

      	//Constructor
      	public Forum()
      	{
      		this.Load += new System.EventHandler(this.Page\_Load);	
      	}
      	
      	
      	private void Page\_Load(object sender, EventArgs e)
      	{
      		Response.Write("Hello");	
      	}		
      			
      	
      	
      }
      

      }

      Nick Parker
      **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


      **

      P Offline
      P Offline
      Paul Riley
      wrote on last edited by
      #2

      I don't get anything like that, I get an overloadride (Duh!) of OnInit() which calls InitializeComponent(). 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; namespace MyNamespace { /// /// Summary description for helpout. /// public class MyPage : System.Web.UI.Page { // control instantiation private void Page_Load(object sender, System.EventArgs e) { // My Code here } #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. /// private void InitializeComponent() { // other initialization here this.Load += new System.EventHandler(this.Page_Load); // and here } #endregion } } Not a hint of a constructor in sight. Paul

      N 1 Reply Last reply
      0
      • P Paul Riley

        I don't get anything like that, I get an overloadride (Duh!) of OnInit() which calls InitializeComponent(). 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; namespace MyNamespace { /// /// Summary description for helpout. /// public class MyPage : System.Web.UI.Page { // control instantiation private void Page_Load(object sender, System.EventArgs e) { // My Code here } #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. /// private void InitializeComponent() { // other initialization here this.Load += new System.EventHandler(this.Page_Load); // and here } #endregion } } Not a hint of a constructor in sight. Paul

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        Paul Riley wrote: I don't get anything like that, I get an overloadride (Duh!) of OnInit() which calls InitializeComponent(). I am going through Programming ASP.NET from O'Reilly's. They used VS.NET for most of their work in the book, however this maybe where they decided to switch things up a little X|. I am trying to learn all the nitty gritty parts to it, w/o the use of the IDE. If you look through it though, a contructor is really all that was needed. :) Nick Parker
        **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


        **

        P 1 Reply Last reply
        0
        • N Nick Parker

          Paul Riley wrote: I don't get anything like that, I get an overloadride (Duh!) of OnInit() which calls InitializeComponent(). I am going through Programming ASP.NET from O'Reilly's. They used VS.NET for most of their work in the book, however this maybe where they decided to switch things up a little X|. I am trying to learn all the nitty gritty parts to it, w/o the use of the IDE. If you look through it though, a contructor is really all that was needed. :) Nick Parker
          **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


          **

          P Offline
          P Offline
          Paul Riley
          wrote on last edited by
          #4

          Ahh, I see now. I'm guessing O'Reilly's were trying to introduce the InitializeComponent() idea to you as it's kind of fundamental to how VS.NET works. That is anything in the "Web Form Designer generated code" region is liable to be edited by the IDE. For WebForms, this includes the call to InitializeComponent (which I do find a bit strange and at times annoying). For Windows Forms the call to InitializeComponent is in the constructor and only the actual generated code appears within the danger region. Paul

          N 1 Reply Last reply
          0
          • P Paul Riley

            Ahh, I see now. I'm guessing O'Reilly's were trying to introduce the InitializeComponent() idea to you as it's kind of fundamental to how VS.NET works. That is anything in the "Web Form Designer generated code" region is liable to be edited by the IDE. For WebForms, this includes the call to InitializeComponent (which I do find a bit strange and at times annoying). For Windows Forms the call to InitializeComponent is in the constructor and only the actual generated code appears within the danger region. Paul

            N Offline
            N Offline
            Nick Parker
            wrote on last edited by
            #5

            Paul Riley wrote: I'm guessing O'Reilly's were trying to introduce the InitializeComponent() idea to you as it's kind of fundamental to how VS.NET works Actually, I just flipped open a section of the book, I have read through most of it, however I just wanted to play w/o the IDE for a bit, I think the section of the book I was in at the time was about ADO.NET stuff. Paul Riley wrote: For WebForms, this includes the call to InitializeComponent (which I do find a bit strange and at times annoying). Right, basically what I was trying to say was that the call itself is rather arbitrary as it isn't even needed if you actually use a constructor properly. :) Oh well. Nick Parker
            **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


            **

            1 Reply Last reply
            0
            • N Nick Parker

              I have been working on creating a forum in C# for ASP.NET recently. I would just like to point out something that doesn't make any sense. Inside the constructor we a whole bunch of extra calls if you use an IDE, why when it's not needed?

              using System;
              using System.Collections;
              using System.Data;
              using System.Web;
              using System.Web.UI;
              using System.Web.UI.WebControls;
              using System.Web.UI.HtmlControls;
              using System.IO;

              namespace DeveloperNotesForum
              {
              public class Forum:System.Web.UI.Page
              {

              	//Constructor
              	public Forum()
              	{
              		Page.Init += new System.EventHandler(Page\_Init);	
              	}
              	
              	private void Page\_Init(object sender, EventArgs e)
              	{
              		InitializeComponent();	
              	}
              	
              	private void InitializeComponent()
              	{
              		this.Load += new System.EventHandler(this.Page\_Load);	
              	}
              	
              	private void Page\_Load(object sender, EventArgs e)
              	{
              		Response.Write("Hello");	
              	}		
              			
              	
              	
              }
              

              }

              But you only have to do this:

              using System;
              using System.Collections;
              using System.Data;
              using System.Web;
              using System.Web.UI;
              using System.Web.UI.WebControls;
              using System.Web.UI.HtmlControls;
              using System.IO;

              namespace DeveloperNotesForum
              {
              public class Forum:System.Web.UI.Page
              {

              	//Constructor
              	public Forum()
              	{
              		this.Load += new System.EventHandler(this.Page\_Load);	
              	}
              	
              	
              	private void Page\_Load(object sender, EventArgs e)
              	{
              		Response.Write("Hello");	
              	}		
              			
              	
              	
              }
              

              }

              Nick Parker
              **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


              **

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #6

              It's because the IDE wants to modify InitializeComponent() without keeping you from accessing the constructor. Very flexible if you ask me... -- Giles wrote: You Scandinavians invaded my home land, like 1500 (+-500) years ago, and kept coming back for more. You should be ashamed of yourselves. Viking Tour, England, 15th July 563. Ticket price: £10 Sold out!

              1 Reply Last reply
              0
              • N Nick Parker

                I have been working on creating a forum in C# for ASP.NET recently. I would just like to point out something that doesn't make any sense. Inside the constructor we a whole bunch of extra calls if you use an IDE, why when it's not needed?

                using System;
                using System.Collections;
                using System.Data;
                using System.Web;
                using System.Web.UI;
                using System.Web.UI.WebControls;
                using System.Web.UI.HtmlControls;
                using System.IO;

                namespace DeveloperNotesForum
                {
                public class Forum:System.Web.UI.Page
                {

                	//Constructor
                	public Forum()
                	{
                		Page.Init += new System.EventHandler(Page\_Init);	
                	}
                	
                	private void Page\_Init(object sender, EventArgs e)
                	{
                		InitializeComponent();	
                	}
                	
                	private void InitializeComponent()
                	{
                		this.Load += new System.EventHandler(this.Page\_Load);	
                	}
                	
                	private void Page\_Load(object sender, EventArgs e)
                	{
                		Response.Write("Hello");	
                	}		
                			
                	
                	
                }
                

                }

                But you only have to do this:

                using System;
                using System.Collections;
                using System.Data;
                using System.Web;
                using System.Web.UI;
                using System.Web.UI.WebControls;
                using System.Web.UI.HtmlControls;
                using System.IO;

                namespace DeveloperNotesForum
                {
                public class Forum:System.Web.UI.Page
                {

                	//Constructor
                	public Forum()
                	{
                		this.Load += new System.EventHandler(this.Page\_Load);	
                	}
                	
                	
                	private void Page\_Load(object sender, EventArgs e)
                	{
                		Response.Write("Hello");	
                	}		
                			
                	
                	
                }
                

                }

                Nick Parker
                **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                **

                P Offline
                P Offline
                Paul Watson
                wrote on last edited by
                #7

                Nick Parker wrote: C# Can be so stupid sometimes... Is that because C# is stupid or because VS.NET is stupid? "Hey HTML sucks, FrontPage puts in all this garbage, so HTML just sucks man" :rolleyes:

                Paul Watson
                Bluegrass
                Cape Town, South Africa

                N 1 Reply Last reply
                0
                • P Paul Watson

                  Nick Parker wrote: C# Can be so stupid sometimes... Is that because C# is stupid or because VS.NET is stupid? "Hey HTML sucks, FrontPage puts in all this garbage, so HTML just sucks man" :rolleyes:

                  Paul Watson
                  Bluegrass
                  Cape Town, South Africa

                  N Offline
                  N Offline
                  Nick Parker
                  wrote on last edited by
                  #8

                  Paul Watson wrote: Is that because C# is stupid or because VS.NET is stupid? "Hey HTML sucks, FrontPage puts in all this garbage, so HTML just sucks man" Very true.... blame it all on VS.NET :laugh: Nick Parker
                  **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                  **

                  1 Reply Last reply
                  0
                  • N Nick Parker

                    I have been working on creating a forum in C# for ASP.NET recently. I would just like to point out something that doesn't make any sense. Inside the constructor we a whole bunch of extra calls if you use an IDE, why when it's not needed?

                    using System;
                    using System.Collections;
                    using System.Data;
                    using System.Web;
                    using System.Web.UI;
                    using System.Web.UI.WebControls;
                    using System.Web.UI.HtmlControls;
                    using System.IO;

                    namespace DeveloperNotesForum
                    {
                    public class Forum:System.Web.UI.Page
                    {

                    	//Constructor
                    	public Forum()
                    	{
                    		Page.Init += new System.EventHandler(Page\_Init);	
                    	}
                    	
                    	private void Page\_Init(object sender, EventArgs e)
                    	{
                    		InitializeComponent();	
                    	}
                    	
                    	private void InitializeComponent()
                    	{
                    		this.Load += new System.EventHandler(this.Page\_Load);	
                    	}
                    	
                    	private void Page\_Load(object sender, EventArgs e)
                    	{
                    		Response.Write("Hello");	
                    	}		
                    			
                    	
                    	
                    }
                    

                    }

                    But you only have to do this:

                    using System;
                    using System.Collections;
                    using System.Data;
                    using System.Web;
                    using System.Web.UI;
                    using System.Web.UI.WebControls;
                    using System.Web.UI.HtmlControls;
                    using System.IO;

                    namespace DeveloperNotesForum
                    {
                    public class Forum:System.Web.UI.Page
                    {

                    	//Constructor
                    	public Forum()
                    	{
                    		this.Load += new System.EventHandler(this.Page\_Load);	
                    	}
                    	
                    	
                    	private void Page\_Load(object sender, EventArgs e)
                    	{
                    		Response.Write("Hello");	
                    	}		
                    			
                    	
                    	
                    }
                    

                    }

                    Nick Parker
                    **The goal of Computer Science is to build something that will last at least until we've finished building it. - Unknown


                    **

                    R Offline
                    R Offline
                    Ray Cassick
                    wrote on last edited by
                    #9

                    Nick Parker wrote: C# Can be so stupid sometimes... Sometimes? :omg::-D

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups