简体   繁体   中英

how .aspx page work and what happens when i send the request to .aspx page first time?

I got stuck here and I want to know how they actually.aspx page work when I send the request for the.aspx page the first time how HTML comes to the browser and when I click on the button what happens behind how the.aspx page gets executed and I want to know does it really need to know this in detail? and how. Does the aspx.cs page work?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write("Welcome");
        }
    }
}



<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="First.aspx.cs" Inherits="sample1.First" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button ID="Button1" runat="server" Text="Click" OnClick="Button1_Click" />
        </div>
    </form>
</body>
</html>

Please go through this: ASP.NET Page Life Cycle Overview

Understanding Page.IsPostBack Property property is also important.

Gets a value that indicates whether the page is being rendered for the first time or is being loaded in response to a postback.

To understand that better, put a breakpoint inside the code written below

protected void Page_Load(object sender, EventArgs e)
{
    if(!IsPostBack)
    {
        // excecutes on page load
    }
    else
    {
        // executes on button click
    }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM