첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ MainPage.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="MainPage.aspx.cs" Inherits="TestProject.MainPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Page 클래스 : Session 속성을 사용해 일정 시간 내 글쓰기 방지하기</title>
    </head>
    <body>
        <form id="form" runat="server">
            <div>
                <asp:TextBox ID="inputTextBox" runat="server" />
                <asp:Button ID="writeButton" runat="server"
                    Text="글 쓰기"
                    OnClick="writeButton_Click" />
                <asp:Label ID="displayLabel" runat="server" />
            </div>
        </form>
    </body>
</html>

 

728x90

 

▶ MainPage.aspx.cs

using System;
using System.Web.UI;

namespace TestProject
{
    /// <summary>
    /// 메인 페이지
    /// </summary>
    public partial class MainPage : Page
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 페이지 로드시 처리하기 - Page_Load(sender, e)

        /// <summary>
        /// 페이지 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        #endregion
        #region 글 쓰기 버튼 클릭시 처리하기 - writeButton_Click(sender, e)

        /// <summary>
        /// 글 쓰기 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void writeButton_Click(object sender, EventArgs e)
        {
            if(Session["WriteTime"] != null)
            {
                DateTime writeTime = Convert.ToDateTime(Session["WriteTime"]);

                TimeSpan timeSpan = DateTime.Now - writeTime;

                if(timeSpan.TotalSeconds < 5)
                {
                    this.displayLabel.Text = "잠시 대기해 주시기 바랍니다.";

                    return;
                }
            }

            Session["WriteTime"] = DateTime.Now;

            this.displayLabel.Text = this.inputTextBox.Text;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요