2018021022453-2-1 PostBack 正確版

3-2-1 PostBack 正確版

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

 

namespace WebApplication1

{

   public partial class WebForm1 : System.Web.UI.Page

   {

       protected void Page_Load(object sender, EventArgs e)

       {

           if (!Page.IsPostBack) //網頁第1次載入執行網頁

           {

               TextBox1.Text = "李大明"; //網頁加載提供TextBox預設值

               lbl_name.Text = TextBox1.Text;

 

               lbl_Status.ForeColor = System.Drawing.Color.Red;

               lbl_Status.Text = "[第一次執行Page Load事件 ] <P>";

           }

           else //網頁第2次載入執行網頁

           {

               lbl_Status.ForeColor = System.Drawing.Color.Blue;

               lbl_Status.Text = "[PostBack 第二次執行Page Load事件] ";

           }

       }

 

       protected void Button1_Click(object sender, EventArgs e)

       {

           lbl_name.Text = TextBox1.Text;

           lbl_Status.Text = lbl_Status.Text + "+ 執行Button_Click事件 <p>";

       }

   }

回應

用生命寫程式,我的程序員,我的路線。

關鍵字





Powered by Xuite
    沒有新回應!