C# Can be so stupid sometimes...
-
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
**
-
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
**
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 -
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. PaulPaul 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
**
-
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
**
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
-
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
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
**
-
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
**
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!
-
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
**
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 -
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 AfricaPaul 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
**
-
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
**
Nick Parker wrote: C# Can be so stupid sometimes... Sometimes? :omg::-D