I’m new to ASP.NET, and I’m trying to create a class that will call in aspx called AddNode.aspx, I have a few questions
- How do I simply print a text in constructor/method, similar to php echo / java system.out.print()
- How do I call the class in AddNode.aspx
- How do I define a function (GetNode()) to return database result?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public class category
{
public category()
{
//
// TODO: Add constructor logic here
//
Response.Write("abc");
}
public static Array[] GetNode() {
}
}
There are indeed great differences between PHP and ASP .NET Web Forms (the differences are less in the case of ASP .NET MVC but they are still much) so I understand the source of confusion.
1-Are you using Web Forms? If so, you can add a Label control to the Form and then set it’s Text property to some value you like. label1.Text = “Hello ASP .NET”;
In the ASPX markup:
<asp:label ID="label1" runat="server" text="Label">In the code behind file (associated with ASPX, right click on the designer and then choose View Code):
You can also use Response.Write(“Hello ASP .NET“); But with this you have less control on where this text appears. Notice you can write HTML tags.
2-You have to distinguish between the class that represents the Web Form (exists in the code-behind file, note the ASP .NET term “code-behind”) and other classes such as the one you made: “category” (in .NET it’s a matter of convention that class names are capitalized: Category).
Call a class? If you mean create an instance of a class for some purpose, just write
category. You can refer to static functionality in the class by writing category.StaticMemberName(); if it’s a method.instance = new category();
3-That’s a multifaceted question. Read about Data access in .NET…
You need to do lots of reading before asking questions like these! Good luck.