Upload
lylien
View
225
Download
2
Embed Size (px)
Citation preview
1
ASP.NET ( C#)
CSIE NTU
2
.NET
3
[] []
4
[] []
5
[] []
6
Web
7
Page
Load
8
Response
WriteRedirect URL
Response.Write("!! ives!!");Response.Redirect("WebForm2.aspx");
9
(1)
10
(2)
Web Form
11
aspx
12
sample5-a1 (1)
WebForm2.aspxWebForm2.aspx WebForm1.aspxprivate void Page_Load(object sender,
System.EventArgs e){
Response.Redirect("WebForm2.aspx");}
13
sample5-a1 (2)
WebForm2.aspxprivate void Page_Load(object sender,
System.EventArgs e){
Response.Write("!! !!");}
14
Label
Label
TextForeColorVisible
15
Button
Button
TextVisible
Click
16
MSDN LibraryMSDN Library [] [][][]MSDN Library F1 http://msdn.microsoft.com/library/http://msdn.microsoft.com/library/cht/
17
sample5-a2
private void submitBTN_Click(object sender,
system.EventArgs e){
string[] fateStr = new string[5] {"","","","",""};Random rnd = new Random();fateLB.Text = fateStr[rnd.Next(0,5)];
}
18
TextBox
TextBox
TextReadOnlyMaxLengthTextMode
SingleLineMultiLinePassword
TextChanged
19
sample5-b1
Response.Redirect
20
Session
Session ID Server Request Session IDServer ID Session
Request
123
123
Request 123
21
Session
Session.SessionID Session IDSession.Timeout Session ()Session.Clear() Session
Session.Add(string name, object value) Session
22
Session
Session.Add(string name, object value)
Ex.Session.Add(name,Alice);
Session[string name]Ex Label1.Text = Session[name].ToString();
23
sample5-a3 (1)
WebForm1.aspxprivate void loginBTN_Click(object sender, System.EventArgs e){
if((idTB.Text == "alice" && pwTB.Text == "alice")||(idTB.Text== "bob" && pwTB.Text == "bob")){
Session.Add("id",idTB.Text);Response.Redirect("WebForm2.aspx");
}}
24
sample5-a3 (2)
WebForm2.aspxprivate void Page_Load(object sender,
System.EventArgs e){
Response.Write(Session["id"].ToString());Response.Write(" !!");
}
25
WebForm2.aspx
Session
26
sample5-b2
WebForm1.aspx WebForm2.aspx Session (null)login.aspx Session
27
(1)
!?
Session
28
(2)
Response.CacheControl = "no-cache";
Page_Load
29
sample5-b3
sample5-b2 ""
Response.CacheControl = no-cache;
30
(1)
Web (C:\Inetpub\wwwroot)
[] [] [Internet Information Services]
31
(2)
Internet Information Services []
32
(3)
[]
33
(4)
URL
http://localhost/ASPNET/
34
(5)
35
(6)
36
(7)
37
(1)
38
(2)
IIS []
39
(3)
[]
40
(1)
(.sln) (.csproj.webinfo)
sample5-b6 D:\ URL http://localhost/sample/
41
(2)
sample
42
(3)
D:\sample5-b6
43
(3)
sample
44
(4)
(.csproj.webinfo) Web URLPath
45
(5)
(.sln)
46
(6)
URL IIS URL
47
LinkButton
LinkButton Button
TextVisible
Click
48
HyperLink
HyperLink
TextImageUrl()NavigateUrlTarget
_blank_parent frameset _search_self_top
49
sample5-a4
WebForm1.aspxprivate void Page_Load(object sender,
System.EventArgs e){
yahooHL.NavigateUrl = "http://tw.yahoo.com";yahooHL.Target = "_blank";
}
50
Image
Image
ImageUrlAlternateText
51
ImageButton
ImageButton Button
ImageUrlAlternateText
Click()
52
sample5-a5 (1)
onmouseover onmouseoutWebForm1.aspx
53
sample5-a5 (2)
WebForm1.aspxprivate void carIB_Click(object sender,
System.Web.UI.ImageClickEventArgs e){
if(e.X
54
sample5-b4
Label Label Visible false Session
55
DropDownList
DropDownList
Items(items ListItemCollection )( ListItem )
AutoPostBack
SelectedIndexChanged( AutoPostBack true)
56
ListItemCollection DropDownList itemsListItemCollection ()exDropDownList1.Items[1]
Count ListItemSelectedItemSelectedIndex
Add (ListItemstring)ClearRemove (ListItemstring)RemoveAt (int)
57
ListItem
ListItemCollection ListItem
TextValueSelected
58
sample5-a6 (1)
WebForm1.aspxstruct star{
public string name;public string country;public string imgUrl;
}
59
sample5-a6 (2)
WebForm1.aspxstar[] myStar = new star[3];private void Page_Load(object sender, System.EventArgs e){
myStar[0].name = "S.H.E";myStar[0].country = "";myStar[0].imgUrl = "she.jpg";myStar[1].name = "";myStar[1].country = "";myStar[1].imgUrl = ".jpg";
60
sample5-a6 (3)
WebForm1.aspxmyStar[2].name = "";myStar[2].country = "";myStar[2].imgUrl = ".jpg";
if(!IsPostBack){
foreach(star starItem in myStar)starDDL.Items.Add(starItem.name);
starDDL.AutoPostBack = true;changeInfo();
}}
61
sample5-a6 (4)WebForm1.aspxprivate void starDDL_SelectedIndexChanged(object sender,
System.EventArgs e){
changeInfo();}private void changeInfo(){
nameLB.Text = myStar[starDDL.SelectedIndex].name;countryLB.Text = myStar[starDDL.SelectedIndex].country;pictureImg.ImageUrl = myStar[starDDL.SelectedIndex].imgUrl;
}
62
ListBox
ListBox DropDownList
Items
( ListItemCollection )SelectionMode
SingleMultiple( Selected true)
63
sample5-a7 (1)
WebForm1.aspxprivate void purchaseBTN_Click(object sender,
System.EventArgs e){
shoppingLB.Items.Add(itemLB.SelectedItem);itemLB.Items.Remove(itemLB.SelectedItem);shoppingLB.SelectedIndex = -1;totalLB.Text = total().ToString();
}
64
sample5-a7 (2)
WebForm1.aspxprivate void cancelBTN_Click(object sender,
System.EventArgs e){
itemLB.Items.Add(shoppingLB.SelectedItem);shoppingLB.Items.Remove(shoppingLB.SelectedItem);itemLB.SelectedIndex = -1;totalLB.Text = total().ToString();
}
65
sample5-a7 (3)
WebForm1.aspxprivate int total(){
int sum = 0;foreach(ListItem item in shoppingLB.Items){
sum += int.Parse(item.Value);}return sum;
}
66
sample5-b5 (1)
JAVA
C#
67
sample5-b5 (2)
SelectedIndexChanged ListBox AutoPostBack true
68
CheckBox
CheckBox
TextTextAlignChecked
CheckedChanged( AutoPostBack true)
69
CheckBoxList
CheckBoxList
Items
( ListItemCollection )RepeatColumnsRepeatDirection
SelectedIndexChanged( AutoPostBack true)
70
RadioButton
RadioButton
TextTextAlignCheckedGroupName
CheckedChanged( AutoPostBack true)
71
RadioButtonList
RadioButton
Items
( ListItemCollection )RepeatColumnsRepeatDirection
SelectedIndexChanged( AutoPostBack true)
72
sample5-a8 (1)
WebForm1.aspxprivate void submitBTN_Click(object sender,
System.EventArgs e){
Session.Add("name",nameTB.Text);Session.Add("sex",sex1RB.Checked?"":"");Session.Add("education", educationRBL.SelectedItem.Text);
73
sample5-a8 (2)
WebForm1.aspxstring hobby = "";foreach(ListItem item in hobbyCBL.Items)
if(item.Selected) hobby+= item.Text +" ";
if(hobby == "") hobby = "";Session.Add("hobby", hobby);
Response.Redirect("WebForm2.aspx");}
74
sample5-a8 (3)
WebForm2.aspxprivate void Page_Load(object sender, System.EventArgs e){
Response.Write(Session["name"].ToString());Response.Write(Session["sex"].ToString() + "!!");Response.Write("
"+Session["education"].ToString() + "");Response.Write("
"+Session["hobby"].ToString());}
75
sample5-b6
ListItem Value