Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

ASP.NET instance


May 13, 2021 ASP.NET


Table of contents


ASP.NET page consists of a large number of server controls as well as HTML controls, text, and images. The sensitive data of the page and the different control states on the page are stored in hidden fields, forming the configuration instructions requested by the page.

ASP.NET controls the association of a page instance with its state at the time of operation. A ASP.NET page is an object of or inherited from a page.

All controls on the page are also objects of related control classes inherited from a parent control. When a page runs, an instance of the object page is created with its content controls.

A ASP.NET page is also a server-.aspx that is stored in the file extension.

It is modular in nature and can be divided into the following core sections:

  • Web page instructions
  • Coded segments
  • The page layout

Page instructions

The page instruction sets the running environment for the page. @ Page directive defines special page properties ASP.NET page parsers and compilers that use the page parser. The page instruction specifies how the page should be handled and specifies the assumptions that need to be made about the page.

It allows you to import namespaces, load assemblies, and register new controls, including custom tag names and namespace prefixes.

Coded segments

Coded segments provide handlers for pages and controls, which are other required features. A s we mentioned, ASP.NET to the object model. N ow, when events occur in the user interface, they fire events, such as a user clicking a button or moving the cursor. T hese events require back-and-forth responses that are encoded in the event handler functionality. Event handlers have little functionality other than binding to space.

Encoding segments or encoding after a file provides routes for all of these event handlers, as well as other features used by developers. Page code can be precompiled and deployed as a binary assembly.

The page layout

The page layout provides the interface of the page. It contains server controls, text, and inline JavaScript and HTML tags.

The following snippets provide an example of a ASP.NET page that explains page instructions, snippets, and page layout written in C#:

<!-- directives -->
<% @Page Language="C#" %>

<!-- code section -->
<script runat="server">

   private void convertoupper(object sender, EventArgs e)
   {
      string str = mytext.Value;
      changed_text.InnerHtml = str.ToUpper();
   }
</script>

<!-- Layout -->
<html>
   <head> 
      <title> Change to Upper Case </title> 
   </head>

   <body>
      <h3> Conversion to Upper Case </h3>

      <form runat="server">
         <input runat="server" id="mytext" type="text" />
         <input runat="server" id="button1" type="submit" value="Enter..." OnServerClick="convertoupper"/>

         <hr />
         <h3> Results: </h3>
         <span runat="server" id="changed_text" />
      </form>

   </body>

</html>

Copy this file to the root of the web server. T he general ones are c: iNETput, wwwroot. When you open the file from your browser and execute it, it produces the following results:

ASP.NET instance

Use visual Studio IDE

Let's expand the same example with visual Studio IDE. You can drag and drop controls directly into the design view without entering code.

ASP.NET instance

The content file is automatically generated. All you have to add is Button1_Click code, as follows:

protected void Button1_Click(object sender, EventArgs e)
{
   string buf = TextBox1.Text;
   changed_text.InnerHtml = buf.ToUpper();
}

The content file code has given:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

   <head runat="server">
      <title>
         Untitled Page
      </title>
   </head>

   <body>

      <form id="form1" runat="server">
         <div>

            <asp:TextBox ID="TextBox1" runat="server" style="width:224px">
            </asp:TextBox>

            <br />
            <br />

            <asp:Button ID="Button1" runat="server" Text="Enter..." style="width:85px" onclick="Button1_Click" />
            <hr />

            <h3> Results: </h3>
            <span runat="server" id="changed_text" />

         </div>
      </form>

   </body>

</html>

Perform this example by right-clicking on the design view, and select 'View in Browser' from the pop-up menu. This produces the following results:

ASP.NET instance