<head>
<title>
alert() 메쏘드 예제
</title>
<SCRIPT LANGUAGE="JavaScript">
alert("메시지를 보여줘요..")
</script>
</head>
<body>
alert() 메소드 예제
</body>
</html>
출처 : 뇌를 자극하는 ASP.NET
ASP.NET에서 제공하는 달력을 쉽게 만들 수 있는 컨트롤 입니다.
<%@ Page Language="C#" %>
<!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> Calendar </title>
<script runat="server">
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
// 바뀌면 날짜선택을 초기화한다.
Calendar1.SelectionMode = (CalendarSelectionMode)DropDownList1.SelectedIndex;
if(Calendar1.SelectionMode == CalendarSelectionMode.None)
Calendar1.SelectedDates.Clear();
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
switch (Calendar1.SelectedDates.Count)
{
case 0: // None
Response.Write("어떤 일자도 선택되지 않았습니다.");
break;
case 1: // Day
Response.Write("선택한 일자"
+ Calendar1.SelectedDate.ToShortDateString()
);
break;
case 7: // Week
Response.Write("선택한 주의 시작 일자"
+ Calendar1.SelectedDate.ToShortDateString()
);
break;
default: // Month
Response.Write("선택한 달의 시작 일자"
+ Calendar1.SelectedDate.ToShortDateString()
);
break;
}
}
protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
{
CalendarDay d = e.Day;
TableCell c = e.Cell;
if (d.IsOtherMonth)
{
c.Controls.Clear();
}
else
{
string message = GetSchedule(d.Date.Month, d.Date.Day);
c.Controls.Add(new LiteralControl("<br />" + message));
}
}
string GetSchedule(int month, int day)
{
string schedule = "";
if (month == 3 && day == 14)
{
schedule = "<a href='http://www.naver.com'>화이트데이</a>";
}
else if (month == 3 && day == 1)
{
schedule = "3.1절";
}
return schedule;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Calendar의 SelectionChange의 이벤트를 사용하는 예제</h3>
<asp:DropDownList ID="DropDownList1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="None">None</asp:ListItem>
<asp:ListItem Value="Day" Selected="True">Day</asp:ListItem>
<asp:ListItem Value="DayWeek">DayWeek</asp:ListItem>
<asp:ListItem Value="DayWeekMonth">DayWeekMonth</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Calendar ID="Calendar1" runat="server" Width="70%" OnSelectionChanged="Calendar1_SelectionChanged" OnDayRender="Calendar1_DayRender" TitleStyle-Font-Size="12px" TitleStyle-Font-Bold="true" DayStyle-VerticalAlign="top" DayStyle-Height="50px" SelectedDayStyle-BackColor="navy"></asp:Calendar>
</div>
</form>
</body>
</html>
참조 : 뇌를자극하는 ASP.NET
html 테그에서 <input type=button ... > 의 형태를 asp.net에서 서버처리하는 컨트롤 입니다.
예제에서는 클라이언트 자바스크립트와 서버에서 호출되는 스크립트가 둘다 처리되는 예제를 볼 수 있습니다.
각각의 스크립트가 처리되는 시간이 어느때인지 유심히 보시면 되겠습니다.
<%@ Page Language="C#" %>
<!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> Button Control </title>
<script runat="server">
protected void btnConfirm_Click(object sender, EventArgs e)
{
//Response.Write("다시 게시 되었습니다.!!");
lblText.Text = "다시 게시 되었습니다.!!";
}
protected void Page_Load(object sender, EventArgs e)
{
btnClient.Attributes.Add("onclick", "confirm('onclick')");
btnClient.Attributes.Add("onmouseover", "document.bgColor='red';");
btnClient.Attributes.Add("onmouseout", "document.bgColor='white';");
}
</script>
<script type="text/javascript">
function ConfirmPostBack()
{
return confirm("다시 게시하시겠습니까?");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Button 예제</h3>
<asp:Button ID="btnConfirm" runat="server" Text="PostBack하기" OnClientClick="return ConfirmPostBack();" OnClick="btnConfirm_Click" /><br />
<br />
<asp:Label ID="lblText" runat="server"></asp:Label><br />
<br />
<br />
<asp:Button ID="btnClient" runat="server" Text="Button" /></div>
</form>
</body>
</html>
참조 : 뇌를 자극하는 ASP.NET p 211
HTML의 List를 출력하는 UL, LI 테그등으로 랜더링 되는 테그들입니다.
3번째 불릿티드 리스트에는 클릭이벤트의 처리를 했습니다.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="p221.aspx.cs" Inherits="p221" %>
<!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>BulletedList</title>
<script runat="server">
protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
{
Response.Write("선택한 목록 번호 : " + e.Index.ToString()
+ "<br />선택한 목록 Value : "
+ BulletedList3.Items[e.Index].Value
+ "<br />선택한 목록 Text : "
+ BulletedList3.Items[e.Index].Text
);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 583px">
<tr>
<td>
<h3>Disc</h3>
<asp:BulletedList ID="BulletedList1" runat="server">
<asp:ListItem>Item #1</asp:ListItem>
<asp:ListItem>Item #2</asp:ListItem>
<asp:ListItem>Item #3</asp:ListItem>
<asp:ListItem>Item #4</asp:ListItem>
</asp:BulletedList>
</td>
<td>
<h3>Circle</h3>
<asp:BulletedList ID="BulletedList2" BulletStyle="Circle" DisplayMode="HyperLink" runat="server">
<asp:ListItem Value="http://daum.net">Item #1</asp:ListItem>
<asp:ListItem Value="http://naver.com">Item #2</asp:ListItem>
<asp:ListItem Value="http://yahoo.co.kr">Item #3</asp:ListItem>
<asp:ListItem Value="http://google.co.kr">Item #4</asp:ListItem>
</asp:BulletedList>
</td>
<td>
<h3>Square</h3>
<asp:BulletedList ID="BulletedList3" BulletStyle="square" DisplayMode="LinkButton" runat="server" OnClick="BulletedList3_Click">
<asp:ListItem>Item #1</asp:ListItem>
<asp:ListItem>Item #2</asp:ListItem>
<asp:ListItem>Item #3</asp:ListItem>
<asp:ListItem>Item #4</asp:ListItem>
</asp:BulletedList>
</td>
<td style="width: 90px">
<h3>Numbered</h3>
<asp:BulletedList ID="BulletedList4" BulletStyle="Numbered" FirstBulletNumber="3" runat="server">
<asp:ListItem>Item #1</asp:ListItem>
<asp:ListItem>Item #2</asp:ListItem>
<asp:ListItem>Item #3</asp:ListItem>
<asp:ListItem>Item #4</asp:ListItem>
</asp:BulletedList>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
출처 : 뇌를 자극하는 ASP.NET p 219
일반적으로 사이트 베너를 표시할때는 자바스크립트나 서버안에서 랜덤처리하는 부분을 구현해서 작업하게 됩니다.
이런 베너출력을 간편하게 처리할 수 있도록 제공되는 컨트롤 입니다.
예제에선 간단한 xml파일을 읽어들이도록 했지만 다른 DataSource를 바인딩할 수 있습니다.
// p219.aspx
<%@ Page Language="C#" %>
<!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>AdRotator</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:AdRotator ID="AdvSection1" runat="server" BorderWidth="1" BorderStyle="Dashed" Height="100px" Width="400px" AdvertisementFile="~/ad.xml" />
</div>
</form>
</body>
</html>
// ad.xml 파일
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Images/bannger1.gif</ImageUrl>
<NavigateUrl>http://www.microsoft.com</NavigateUrl>
<AlternateText>마소</AlternateText>
<Keyword>Microsoft</Keyword>
<Impressions>50</Impressions>
</Ad>
<Ad>
<ImageUrl>~/Images/bannger2.gif</ImageUrl>
<NavigateUrl>http://www.i-ruru.com</NavigateUrl>
<AlternateText>루루</AlternateText>
<Keyword>ruru</Keyword>
<Impressions>60</Impressions>
</Ad>
<Ad>
<ImageUrl>~/Images/bannger3.gif</ImageUrl>
<NavigateUrl>http://www.allblog.net</NavigateUrl>
<AlternateText>올블로그</AlternateText>
<Keyword>allblog</Keyword>
<Impressions>50</Impressions>
</Ad>
</Advertisements>