스크립트매니져 화면에 렌더링 되지 않음
ScriptManager
- Ajax 처리에 관련된 모든 자바스크립트 코드를 자동으로 생성하는 역할
UpdatePanel
- Ajax 처리를 하고 싶은 영역을 묶는 역할
페이지 전환 없이 동적으로 데이터를 주고받는다.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex07.aspx.cs" Inherits="Ex07" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
이름 :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
이름 :
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" />
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Ex07 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = TextBox1.Text + "님 . 현재 시간은 " + DateTime.Now.ToString() + "입니다.";
}
protected void Button2_Click(object sender, EventArgs e)
{
Label2.Text = TextBox2.Text + "님. 현재 시간은 " + DateTime.Now.ToString() + "입니다.";
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex08.aspx.cs" Inherits="Ex08" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Ex08.aspx<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
</h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h2>
아이디 :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button"
Width="189px" />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</h2>
</ContentTemplate>
</asp:UpdatePanel>
<h2>
<br />
</h2>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Ex08 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//아이디 중복검사
if (TextBox1.Text == "hong" || TextBox1.Text == "test")
{
Label1.Text = "이미 존재하는 아이디.";
}
else
{
Label1.Text = "사용 가능한 아이디";
}
}
}
ajax컨트롤을 통하여 동적으로 생성 db접근도 실시간 접근 가능
DropDownList1 만 오토 포스트백을 True로 변경
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex09.aspx.cs" Inherits="Ex09" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Ex09.aspx</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h2>
동이름 :
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="검색"
Width="135px" />
<br />
<br />
선택 :
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged1">
</asp:DropDownList>
<br />
<br />
결과 :
<asp:TextBox ID="TextBox2" runat="server" Width="585px"></asp:TextBox>
</h2>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class Ex09 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//검색결과 출력
SqlConnection con = new SqlConnection();
con.ConnectionString = ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = string.Format("select ZIPCODE, '[' + ZIPCODE + '] ' + SIDO + ' ' + GUGUN + ' ' + DONG + ' ' + ISNULL(BUNJI,'') as [item] from zipcode where DONG like '%{0}%'", TextBox1.Text);
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
DropDownList1.Items.Clear();//초기화
while (reader.Read())
{
DropDownList1.Items.Add(reader["item"].ToString());
}
reader.Close();
con.Close();
}
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
//결과 주소 1개 선택
TextBox2.Text = DropDownList1.SelectedItem.ToString();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex10.aspx.cs" Inherits="Ex10" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Ex10.aspx<br />
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</h2>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966"
BorderStyle="None" BorderWidth="1px" CellPadding="4"
DataSourceID="SqlDataSource1" Width="800px">
<Columns>
<asp:BoundField DataField="ZIPCODE" HeaderText="ZIPCODE"
SortExpression="ZIPCODE" />
<asp:BoundField DataField="SIDO" HeaderText="SIDO" SortExpression="SIDO" />
<asp:BoundField DataField="GUGUN" HeaderText="GUGUN" SortExpression="GUGUN" />
<asp:BoundField DataField="DONG" HeaderText="DONG" SortExpression="DONG" />
<asp:BoundField DataField="BUNJI" HeaderText="BUNJI" SortExpression="BUNJI" />
<asp:BoundField DataField="SEQ" HeaderText="SEQ" SortExpression="SEQ" />
</Columns>
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<SortedAscendingCellStyle BackColor="#FEFCEB" />
<SortedAscendingHeaderStyle BackColor="#AF0101" />
<SortedDescendingCellStyle BackColor="#F6F0C0" />
<SortedDescendingHeaderStyle BackColor="#7E0000" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:conStr %>"
SelectCommand="SELECT * FROM [zipcode]"></asp:SqlDataSource>
<h2>
<br />
<br />
</h2>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
</div>
</form>
</body>
</html>
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ex11.aspx.cs" Inherits="Ex11" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2>
Ex11.aspx</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<h2>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:Timer ID="Timer1" runat="server" Interval="1000" ontick="Timer1_Tick">
</asp:Timer>
</h2>
</ContentTemplate>
</asp:UpdatePanel>
<br />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Ex11 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Timer1_Tick(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
}
다운받은것을 탭추가로 새로 탭을 만들어 항목 선택후 다운받은 dll파일을 추가하게되면 ajax 컨트롤들을 가져올수 있다.