簡體   English   中英

.aspx 頁面如何工作以及當我第一次將請求發送到.aspx 頁面時會發生什么?

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

我被困在這里,我想知道當我第一次發送對 .aspx 頁面的請求時,它們實際上是如何工作的被執行,我想知道它真的需要詳細了解嗎? 如何。 aspx.cs 頁面是否有效?

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>

請 go 通過此: ASP.NET 頁面生命周期概述

了解Page.IsPostBack Property屬性也很重要。

獲取一個值,該值指示頁面是第一次呈現還是正在加載以響應回發。

為了更好地理解這一點,請在下面編寫的代碼中放置一個斷點

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM