2008년 01월 03일
[닷넷 웹서비스 예제] Default.aspx
Last Modified |
Default.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 30 41 42 43 44 45 46 47 48 49 50 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 91 92 | <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1{ font-family: HY견고딕; } .style2{ font-family: Verdana; font-weight: bold; } .style3{ font-family: Verdana; } .style4{ font-family: 돋움; } .style5{ font-family: 돋움; font-weight: bold; } </style> </head> <body> <form id="form1" runat="server"> <div> <br /> <h1> <span class="style2">Convert Temperatures</span></h1> <span class="style5">Temperature</span><span class="style4"> : </span><span class="style3"><span class="style1"><span class="style4"> <asp:TextBox ID="TemperatureTextbox" runat="server"></asp:TextBox> </span></span></span><span class="style4"> </span><span class="style1"><span class="style3"><span class="style4"> <asp:Button ID="ConvertButton" runat="server" onclick="ConvertButton_Click" Text="Convert" /> </span></span></span> <br class="style4" /> <br class="style4" /> <span class="style4">The following displays the value you converted as indicated :</span><br class="style4" /> <br class="style4" /> <span class="style5">Fahrenheit -> Celsius</span><span class="style4"> : <asp:Label ID="FahrenheitLabel" runat="server"></asp:Label> </span> <br class="style4" /> <span class="style5">Celsius -> Fahrenheit</span><span class="style4"> : <asp:Label ID="CelsiusLabel" runat="server"></asp:Label> </span> <br /> <br /> </div> </form> </body> </html> |
1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
1) @Page directive
+ *.aspx 파일이 웹 폼 페이지라는 것을 의미.
+ Code Behind File 을 .aspx 파일에 연결하려면 @Page 지시문과 Inherits, CodeFile 특성을 사용해야 한다.
+ Attributes
- Language : 페이지 내의 모든 인라인 렌더링 (<% %> 및 <%= %>) 및 코드 선언 블록을 컴파일하는데 사용하는 언어.
VB, C#, JScript 를 포함하여 .NET Framework에서 지원되는 모든 언어를 나타낼 수 있지만
각 페이지에 대해 언어를 하나만 사용하고 지정할 수 있다.
- CodeFile : 클래스가 들어있는 언어별 파일의 경로
- AutoEventWireUp : 페이지의 이벤트가 자동으로 연결되는지 여부를 나타낸다. 기본값은 true.
true이면 Page_Init 이나 Page_Load 등의 페이지 이벤트를 자동으로 호출한다.
ASP.NET 에서 이벤트는 무조건 실행되는 것이 아니라 이벤트 핸들러에 이벤트 핸들러 메서드가
연결이 되어야만 실행이 가능하다.
이벤트 핸들러에 이벤트 핸들러 메서드를 연결하는 간단하게 다음과 같다.
this.Load += new System.Web.UI.EventHandler(this.Page_Load)
그러나 위의 코드를 사용하지 않고도 AutoEventWireUp 의 기본값(true) 때문에Page_Load 라는 이벤트 핸드러 메서드는 자동으로 실행된다.
자세한 내용은
- Inherits : MyCodeBehind 클래스. 코드 비하인드 파일에 구현된 클래스 이름을 지정한다.
상속할 페이지에 대한 Code Behind Class를 정의하며 이 클래스는 Page클래스에서 파생된 모든 클래스일 수 있다.
Code Behind Class 에 대한 자세한 설명은 ASP.NET 웹 페이지 코드 모델을 참조.
41. <form id="form1" runat="server">
- <Form> 태그 : ASP와는 달리 <form>태그는 웹 폼 페이지에 하나만 존재할 수 있다.
48. <asp:TextBox ID="TemperatureTextbox" runat="server"></asp:TextBox>
1) Server Control 이란?
: Tag 의 Attribute 에 runat="server" 를 갖는 것.
서버가 runat="server" 을 인식하는 즉시 그 객체를 메모리에 생성한다.
+ 컨트롤 종류
- HTML Server controls
- Web Server controls
- Validation controls
- User controls
① HTML Server controls
- HTML Server Control을 디자인 뷰를 통해서 보게 되면 사실 일반적인 HTML과 다른 점을 찾을 수 없다.
HTML 은 클라이언트의 브라우저를 통해 해석되고 보여지는 Tag 이므로 서버에서 직접적으로 컨트롤 하기 어렵기 때문에
그 동안은 자바스크립트와 같은 클라이언트 스크립트를 통해서 제어를 해왔다.
runat="server"를 추가해서서 이제는 HTML 을 서버 타입으로 간단하게 변경하여 서버 프로그램을 통해 제어 할 수 있다.
② Web Server controls
- 특징 : Attribute에 runat="server"를 갖는다.
필요에 의해 Web Page 에 설치되면 ASP.NET Runtime 에 의해 server에서 handled 된다.
코드 상에서 Controls 를 참조하기 위해 Attribute 의 ID 값을 이용한다.
반드시 짝으로 태그가 이루어져야 한다. ex. <asp:Label id ="aa" runat="server"/>
<REFERENCE>
http://www.hoons.kr/Lectureview.aspx?key=Lecture&LECCATE_IDX=8&ref=1&lecture_idx=145
http://blog.naver.com/netbookmark/20031781344
# by | 2008/01/03 16:11 | [P] Web Services | 트랙백 | 덧글(0)





☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]