ASP.NET/Calling a class within C#
-
Hello, I have a class that I'm trying to call from a CodeBehind page it goes something like this: using System; using System.Data; using System.Data.SqlClient; namespace ReDirectASPX.MainFuse.Functions { /// /// Summary description for MainFuse. /// public class MainFuse : System.Web.UI.Page { public MainFuse() { // // TODO: Add constructor logic here :: Base constructor // } public void AddDatabaseEntry(string URLMapTo, string ReDirectURL) { //Add some code here for the DB connection and the DB add }//end AddDatabaseEntry() } } When I call this class as referenced in another post http://forums.asp.net/934046/ShowPost.aspx[^] I get an invalid Token error like this: Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry(); Invalid token '(' in class, struct, or interface member declaration Any suggestions would be great Thanks, -T Nino -- modified at 16:58 Saturday 8th October, 2005
-
Hello, I have a class that I'm trying to call from a CodeBehind page it goes something like this: using System; using System.Data; using System.Data.SqlClient; namespace ReDirectASPX.MainFuse.Functions { /// /// Summary description for MainFuse. /// public class MainFuse : System.Web.UI.Page { public MainFuse() { // // TODO: Add constructor logic here :: Base constructor // } public void AddDatabaseEntry(string URLMapTo, string ReDirectURL) { //Add some code here for the DB connection and the DB add }//end AddDatabaseEntry() } } When I call this class as referenced in another post http://forums.asp.net/934046/ShowPost.aspx[^] I get an invalid Token error like this: Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry(); Invalid token '(' in class, struct, or interface member declaration Any suggestions would be great Thanks, -T Nino -- modified at 16:58 Saturday 8th October, 2005
-
Hi there, You might need to double check the syntax of your sample code and see what causes this compiler error. If you cannot find anything, then you might want to post some code snippets of the MainFuse class that is causing the error at the moment.
Hi min, Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry**(URLMapTo,** ReDirectURL**)**; This is the callout with the parameters added. It's telling me that the opening '(' and delimter ',' and the closing ')' are causing this error. Not sure why. Nino
-
Hi min, Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry**(URLMapTo,** ReDirectURL**)**; This is the callout with the parameters added. It's telling me that the opening '(' and delimter ',' and the closing ')' are causing this error. Not sure why. Nino
-
Nino_1 wrote: Tony.AddDatabaseEntry(URLMapTo, ReDirectURL); Where do you put this sample code? Inside a method body or outside?
minhpc_bk wrote: Where do you put this sample code? Inside a method body or outside? I wish I could say but, here's the source code:
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; //Added class here that's called Mainfuse using ReDirectASPX.MainFuse.Functions; namespace ReDirectASPX { /// /// Summary description for addurlmappings. /// This codepage will redirect all mappings and send them to correct URLMapping. /// public class addurlmappings : System.Web.UI.Page { public System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { // if (!IsPostBack) // DataSub(); }//End PageLoad // void DataSub() // { // //Data Sub Code Goes Here // // }//End DataSub // // void Edit (object sender, HTMLEditCommands e) // { // // }//End EditCommand // // void Change (object sender, HTMLEditCommands e) // { // // }//End ChangeCommand // // void Update (object sender, HTMLEditCommands e) // { // // }//End UpdateCommand Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry(URLMapTo, ReDirectURL); #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() { this.Load += new System.EventHandler(this.Page_Load); } #endregion }//end class }//end namespace
Nino -- modified at 1:04 Tuesday 11th October, 2005
-
minhpc_bk wrote: Where do you put this sample code? Inside a method body or outside? I wish I could say but, here's the source code:
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; //Added class here that's called Mainfuse using ReDirectASPX.MainFuse.Functions; namespace ReDirectASPX { /// /// Summary description for addurlmappings. /// This codepage will redirect all mappings and send them to correct URLMapping. /// public class addurlmappings : System.Web.UI.Page { public System.Web.UI.WebControls.DataGrid DataGrid1; private void Page_Load(object sender, System.EventArgs e) { // if (!IsPostBack) // DataSub(); }//End PageLoad // void DataSub() // { // //Data Sub Code Goes Here // // }//End DataSub // // void Edit (object sender, HTMLEditCommands e) // { // // }//End EditCommand // // void Change (object sender, HTMLEditCommands e) // { // // }//End ChangeCommand // // void Update (object sender, HTMLEditCommands e) // { // // }//End UpdateCommand Mainfuse Tony = new MainFuse(); Tony.AddDatabaseEntry(URLMapTo, ReDirectURL); #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() { this.Load += new System.EventHandler(this.Page_Load); } #endregion }//end class }//end namespace
Nino -- modified at 1:04 Tuesday 11th October, 2005
Nino, You cannot place the sample code to invoke a method such as the AddDatabaseEntry outside of the body of a method in the class denition. Though you can put the sample code as below:
Mainfuse Tony = new MainFuse();
outside the body of a method/property of the class as it just declares a member named
Tony
for the classaddurlmappings
. However, when you want to invoke a method of theTony
member, you have to put the sample code in a method of the class like the constructor or any other methods Page_Load, OnInit .... For more information, you can see 10. Classes[^] -
Nino, You cannot place the sample code to invoke a method such as the AddDatabaseEntry outside of the body of a method in the class denition. Though you can put the sample code as below:
Mainfuse Tony = new MainFuse();
outside the body of a method/property of the class as it just declares a member named
Tony
for the classaddurlmappings
. However, when you want to invoke a method of theTony
member, you have to put the sample code in a method of the class like the constructor or any other methods Page_Load, OnInit .... For more information, you can see 10. Classes[^]minhpc_bk wrote: You cannot place the sample code to invoke a method such as the AddDatabaseEntry outside of the body of a method in the class denition. Though you can put the sample code as below:
minhpc_bk wrote:
Mainfuse Tony = new MainFuse();minhpc_bk wrote: outside the body of a method/property of the class as it just declares a member named Tony for the class addurlmappings. However, when you want to invoke a method of the Tony member, you have to put the sample code in a method of the class like the constructor or any other methods Page_Load, OnInit .... I'm not quite sure how to proceed, does the entire block go into the Page_Load method ? Nino -- modified at 10:56 Tuesday 11th October, 2005
-
minhpc_bk wrote: You cannot place the sample code to invoke a method such as the AddDatabaseEntry outside of the body of a method in the class denition. Though you can put the sample code as below:
minhpc_bk wrote:
Mainfuse Tony = new MainFuse();minhpc_bk wrote: outside the body of a method/property of the class as it just declares a member named Tony for the class addurlmappings. However, when you want to invoke a method of the Tony member, you have to put the sample code in a method of the class like the constructor or any other methods Page_Load, OnInit .... I'm not quite sure how to proceed, does the entire block go into the Page_Load method ? Nino -- modified at 10:56 Tuesday 11th October, 2005
Nino_1 wrote: I'm not quite sure how to proceed, does the entire block go into the Page_Load method ? First of all, I guess that you understand the syntax of a class definition, I mean you basically know how to declare a member of a class or a local variable of a method. And if you want to invoke a method of an object, you'll normally place the sample code in the body of a method so that when the method of the parent class is invoked your sample code also executes. Secondly, i guess you might be confused about where to put your sample code to invoke the AddDatabaseEntry method of the Tony member to do the job. That all depends on when you want it to execute, it would also mean you should undertand how the web page is processed during the life cycle of the request, and you should be familiar with the order of the page events so that you can choose when to execute your sample code properly. For example, you can choose the Page_Load to run your sample code when the page is just loaded or when the click event of a button is processed. For more information, you can see: Web Forms Page Processing[^] Control Execution Lifecycle[^]