ASP.NET - Hello World Example

Here's an example code snippet in C# using ASP.NET that will display the "Hello, World!" text on a web page:

  • Open Visual Studio and create a new ASP.NET Web Application project.
  • In the Solution Explorer, open the Default.aspx.cs file.
  • Add the following code to the Page_Load method:
protected void Page_Load(object sender, EventArgs e)
{
    Response.Write("Hello, World!");
}
  • Save the changes and run the application.
  • In a web browser, navigate to http://localhost:/Default.aspx to view the "Hello, World!" text on the web page.

Note: Replace with the actual port number your application is running on, which can be found in the project properties or the URL when you run the application.

Another example code snippet in C# using ASP.NET that will display the text entered in a textbox after a button is clicked:

  • Open Visual Studio and create a new ASP.NET Web Application project.
  • In the Solution Explorer, open the Default.aspx file.
  • Add the following code to create a textbox and a button:
<asp:TextBox ID="txtMessage" runat="server"></asp:TextBox>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
  • In the Default.aspx.cs file, add the following code to the btnSubmit_Click event handler:
protected void btnSubmit_Click(object sender, EventArgs e)
{
    string message = txtMessage.Text;
    Response.Write(message);
}
  • Save the changes and run the application.
  • In a web browser, enter some text in the textbox and click the "Submit" button. The text will be displayed on the web page.
  • Note: You can customize the code to display the text in a different way, such as in a label or a separate page.