Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

ASP.NET Web Page Forms:


In ASP.NET, web page forms are used to collect and submit user input. Let's create a simple example of a web page with a form using ASP.NET Web Forms.

Example: Creating a Web Page Form in ASP.NET Web Forms

  1. Set Up Your Project:

    • Open Visual Studio and create a new ASP.NET Web Application project.
    • Choose Web Forms as the project template.
  2. Design Your Web Page with a Form:

    • Open Default.aspx in the Visual Studio designer.
    • Add HTML form elements (e.g., textboxes, buttons) to collect user input.
  3. Example

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="YourProjectName._Default" %>

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
    <title>ASP.NET Web Page with Form</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <label for="txtName">Name:</label>
    <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
    <br />
    <label for="txtEmail">Email:</label>
    <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
    <br />
    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    </div>
    </form>
    </body>
    </html>

  4. Write Server-side Code:
    • Open Default.aspx.cs (code-behind file) in Visual Studio.
    • Write C# code to handle form submission and process user input.
  5. Example

    using System;

    namespace YourProjectName
    {
    public partial class _Default : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
    // Retrieve user input from textboxes
    string name = txtName.Text;
    string email = txtEmail.Text;

    // Process user input (e.g., save to database, send email, etc.)
    // For simplicity, let's just display a message
    Response.Write($"Thank you, {name}, for submitting your email ({email})!");
    }
    }
    }

  6. Run Your Application:
    • Build and run your ASP.NET web application.
    • Navigate to the Default.aspx page in your browser.
    • Fill out the form and click the "Submit" button.
    • You should see a message displayed on the page thanking the user for submitting their input.

That's it! You've created a simple ASP.NET web page with a form. Users can enter their name and email, and server-side code processes the form submission. This example demonstrates the basic concept of using forms in ASP.NET to collect user input.


Advertisement
Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java