ASP.NET 으로 웹페이지 제작할 때 페이지 화면에 만들어지는 모든 UI를 ASP.NET 서버 컨트롤이라 하고 

일반적으로 많이 쓰이는 컨트롤러 그룹을 묶어 표준 컨트롤이라고 한다.


표준 컨트롤러에 대하여 알아보자 


우선 화면에 출력하는 방법 3가지를 알아보자

물론 화면에는 동일하게 출력 될 것입니다.~


test9.aspx


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test9.aspx.cs" Inherits="FrmText.test9" %>
 
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <h1>표준 컨트롤러</h1>
        
        <h2>방법 [1] 순수 HTML 사용해서 버튼 만들기</h2>
        <input type="button" name="name" value="버튼1" />
 
        <h2>방법 [2] runat 속성을 추가해서 서버 컨트롤 버튼 만들기</h2>
        <input type="button" id="btnHtml" runat="server" value="버튼2" />
 
        <h2>방법 [3] ASP.NET 표준 컨트롤러를 사용해서 버튼 만들기</h2>
        <asp:Button Text="버튼3" runat="server" ID="btnServer"/>
 
    </div>
    </form>
</body>
</html>
 
cs



test9.aspx.cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace FrmText
{
    public partial class test9 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnHtml.Value = "Html ServerControll Button";
            btnServer.Text = "표준 컨트롤 버튼";
        }
    }
}
cs


출력화면



Response.Write()

- 페이지의 문자열을 출력하거나 , 자바스크립트도 실행 할 수 있습니다.


Response.Redirect()

- 지정된 페이지로 이동합니다. 


test2.aspx



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test2.aspx.cs" Inherits="FrmText.test2" %>
 
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
        </div>
        <p>
            <asp:Button ID="Button1" runat="server" Text="버튼1" OnClick="btn1" />
            <%="버튼1을 클릭하세요<br />" %>
        </p>
        <p>
            <asp:Button ID="Button2" runat="server" Text="버튼2" OnClick="btn2" />
            <%="버튼2을 입력하세요<br />" %>
        </p>
        <p>
            <asp:Button ID="Button3" runat="server" Text="버튼3" OnClick="btn3" />
            <%="링크로 이동하겠습니다.<br />" %>
        </p>
    </form>
</body>
</html>
 
cs



test2.aspx.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
namespace FrmText
{
    public partial class test2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("<h1>안녕하세요 내장객체 예제 입니다.<h1/>");
        }
        protected void btn1(object sender,EventArgs e)
        {
            Response.Write("<p style='color:skyblue;'>버튼 1이 클릭되었습니다.</p><br />");
        }
        protected void btn2(object sender,EventArgs e)
        {
            string str = @"
            <script>
                alert('alert 이벤트');
            </script>
        ";
            Response.Write(str);
        }
        protected void btn3(object sender,EventArgs e)
        {
            string Url = "http://kingchobocoding.tistory.com/";
            Response.Redirect(Url);
        }
 
    }
}
cs


화면


버튼 1을 눌렀을 때 CSS를 적용하여 텍스트가 출력 되었습니다.



버튼 2을 눌렀을 때 스크립트가 실행합니다 (alert 이벤트)

3번 버튼을 클릭하시면 네이버로 이동하는걸 볼 수 있습니다. 



+ Recent posts