■ Style 클래스를 사용해 스타일 설정하기

------------------------------------------------------------------------------------------------------------------------

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>Style 클래스를 사용해 스타일 설정하기</title>

    </head>

    <body>

        <form id="form" runat="server">

            <div>

                <br />

                테스트 문자열 입니다.

                <br />

                <br />

                <asp:Button ID="postbackButton" runat="server"

                    Text="Postback" />

                <asp:Button ID="reloadButton" runat="server"

                    Text="Reload" />

            </div>

        </form>

    </body>

</html>

 

 

MainPage.aspx.cs

 

 

using System;

using System.Drawing;

using System.Web.UI;

using System.Web.UI.WebControls;

 

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)

        {

            Style buttonStyle = new Style();

 

            buttonStyle.ForeColor = Color.Red;

            buttonStyle.Font.Size = 12;

            buttonStyle.Font.Name = "나눔고딕코딩";

 

            Page.Header.StyleSheet.RegisterStyle(buttonStyle, null);

 

            this.postbackButton.CssClass = buttonStyle.RegisteredCssClass;

            this.reloadButton.CssClass   = buttonStyle.RegisteredCssClass;

 

            Style divStyle = new Style();

 

            divStyle.ForeColor   = Color.Blue;

            divStyle.Font.Size   = 12;

            divStyle.Font.Name   = "나눔고딕코딩";

 

            Page.Header.StyleSheet.CreateStyleRule(divStyle, null, "body, div");

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요