FrmPageLoad
.NET프로그래밍/ASP.NET 3.5 SP1 2009. 10. 5. 20:38 |
==> [FrmPageLoad.aspx] 소스 및 디자인
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FrmPageLoad.aspx.cs" Inherits="FrmPageLoad" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnPostBack" runat="server" Text="다시 게시(PostBack)"
onclick="btnPostBack_Click" />
<asp:Button ID="btnNewLoad" runat="server" Text="다시 로드"
onclick="btnNewLoad_Click" />
</div>
</form>
</body>
</html>
-------------------------------------------------------------------------------------
==> [FrmPageLoad.aspx.cs] 소스
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class FrmPageLoad : System.Web.UI.Page
{
// 처음 로드(NewLoad)와 다시 게시(PostBack)
protected void Page_Load(object sender, EventArgs e)
{
// 처음 로드된 상태라면
if (Page.IsPostBack == false) // 다시 게시가 아니라면,
{
Response.Write("[1] 처음 로드되었습니다.<br />");
}
if (!Page.IsPostBack)
{
Response.Write("[2] 처음 로드되었습니다.<br />");
}
if (!IsPostBack)
{
Response.Write("[3] 처음 로드되었습니다.<br />");
}
// 다시 게시 상태라면
if (Page.IsPostBack == true) // 다시 게시된 상태 / 기본값(처음의 값)은 'false' 이다.
{
Response.Write("[4] 포스트백(다시게시) 되었습니다.<br />");
}
// 처음로드 <> 다시게시
if (!Page.IsPostBack)
{
Response.Write("[5] 처음 로드되었습니다.<br />");
}
else
{
Response.Write("[6] 포스트백(다시게시) 되었습니다.<br />");
}
//[!] Page_Load() 이벤트 처리기는 처음로드하거나 버튼이 클릭할 때마다 실행
Response.Write("[7] 폼이 로드할 때마다 실행<br />");
}
protected void btnPostBack_Click(object sender, EventArgs e)
{
// Page.ClientScript.RegisterclientScriptBlock() : 자바스크립트 호출
string strJs = @"
<script>
alert('포스트백');
</script>
";
// Page 생략가능
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "msg", strJs);
}
protected void btnNewLoad_Click(object sender, EventArgs e)
{
// 현재 페이지로 다시 이동 : 다시 로드
Response.Redirect(Request.ServerVariables["SCRIPT_NAME"]); //
}
}
-------------------------------------------------------------------------------------
[실행결과]
--> 처음 실행화면
--> "다시 게시(PostBack)"버튼을 누른 후 결과
--> "다시 로드"버튼을 누른 후 결과
'.NET프로그래밍 > ASP.NET 3.5 SP1' 카테고리의 다른 글
FrmLabelTextBoxButton(레이블 / 텍스트박스 / 버튼) (0) | 2009.10.06 |
---|---|
WebStandardControl(표준 컨트롤) 시작 (0) | 2009.10.06 |
ASP.NET 주요 내장 개체(클래스)들 - Page클래스 (0) | 2009.10.05 |
FrmApplicationSession (0) | 2009.10.05 |
ASP.NET 주요 내장 개체(클래스)들 - Application 개체와 Session 개체 (0) | 2009.10.05 |