1
.NET
利 [] [] 來 說 切 切 理
[] [ ] 來 說 拉 類 類
[] [ ] 列 連
Web 行流 來 了 不 不 不 流 立 行
Page 類 Load 理
Response 類 Write 料 Redirect URL Response.Write("!! ives!!"); Response.Redirect("WebForm2.aspx");
(1)
(2) Web Form
aspx
例 sample5-a1 (1) WebForm2.aspx WebForm2.aspx 列 WebForm1.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Redirect("WebForm2.aspx"); }
例 sample5-a1 (2) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Write("!! 臨!!"); }
Label Label 來 Text ForeColor Visible
Button Button Text Visible Click
MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/
例 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)]; }
TextBox TextBox 料 Text ReadOnly MaxLength 度 TextMode SingleLine 行 MultiLine 行 Password TextChanged 更
練 sample5-b1 易 留 料 念 立 利 料 利 Response.Redirect 料
Session 念 連 Session ID 料 料 Server Request 都 Session ID Server ID 來索 Session
Session Session.SessionID 來識 Session ID Session.Timeout Session () Session.Clear() Session Session.Add(string name, object value) Session
Session 立 Session.Add(string name, object value) Ex.Session.Add( name, Alice ); Session[string name] Ex Label1.Text = Session[ name ].ToString();
例 sample5-a3 (1) 列 WebForm1.aspx private 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"); } }
例 sample5-a3 (2) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Write(Session["id"].ToString()); Response.Write(" 臨!!"); }
列 列 WebForm2.aspx 不 若 離 Session
練 sample5-b2 列 念 WebForm1.aspx WebForm2.aspx Session ( null) 不 login.aspx Session 料
(1) 了!? Session 利
(2) Response.CacheControl = "no-cache"; 不 Page_Load
練 sample5-b3 sample5-b2 " " 念 利 Response.CacheControl = no-cache ;
錄 (1) Web (C:\Inetpub\wwwroot) 料 錄 錄 [ ] [ 理 ] [Internet Information Services]
錄 (2) Internet Information Services 料 [ ] 錄
錄 (3) [ ] 立 錄
錄 (4) 錄 錄 URL http://localhost/aspnet/
錄 (5) 錄
錄 (6)
錄 (7) 錄
立 錄 (1) 錄 錄 錄 錄 列
立 錄 (2) IIS 錄 料 []
立 錄 (3) [ 立 ] 錄 立
行 例 (1) 行 例 更 例 (.sln) (.csproj.webinfo) 錄 例 行 例 sample5-b6 D:\ 行 URL http://localhost/sample/
行 例 (2) 立 錄 sample
行 例 (3) 立 錄 錄 D:\sample5-b6
行 例 (3) 錄 錄 sample
行 例 (4) (.csproj.webinfo) Web URLPath 路
行 例 (5) (.sln) 若 例 立 不
行 例 (6) 行 例 利 例 行 行 若 不 更 例 URL IIS 立 例 URL 錄
LinkButton LinkButton 連 Button Text Visible Click
HyperLink HyperLink 來 立 連 Text ImageUrl ( ) NavigateUrl 連 Target 連 _blank _parent frameset _search _self 連 _top
例 sample5-a4 易 連 WebForm1.aspx private void Page_Load(object sender, System.EventArgs e) { yahoohl.navigateurl = "http://tw.yahoo.com"; yahoohl.target = "_blank"; }
Image Image 來 ImageUrl AlternateText
ImageButton ImageButton Button ImageUrl AlternateText Click ( 理 參數 滑 )
例 sample5-a5 (1) 利 onmouseover onmouseout WebForm1.aspx <asp:imagebutton onmouseover="this.src='carlogo.jpg' " onmouseout="this.src='cartext.jpg' "
例 sample5-a5 (2) WebForm1.aspx private void carib_click(object sender, System.Web.UI.ImageClickEventArgs e) { if(e.x<=100) textlb.text = " 來 BMW!!"; else textlb.text = " 來 BENZ!!"; }
練 sample5-b4 念 數 Label Label Visible false 數 Session
DropDownList DropDownList 拉 Items 拉 (items ListItemCollection 類 ) ( ListItem 類 ) AutoPostBack 更 SelectedIndexChanged 更 ( AutoPostBack true)
ListItemCollection 類 DropDownList items ListItemCollection 類 () 索 ex DropDownList1.Items[1] Count ListItem 數 SelectedItem SelectedIndex 索 Add (ListItem string) Clear Remove (ListItem string) RemoveAt 索 (int)
ListItem 類 ListItemCollection 類 ListItem 類 Text Value 聯 Selected
例 sample5-a6 (1) WebForm1.aspx struct star { public string name; public string country; public string imgurl; }
例 sample5-a6 (2) WebForm1.aspx star[] 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";
例 sample5-a6 (3) WebForm1.aspx mystar[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(); }
例 sample5-a6 (4) WebForm1.aspx private 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; }
ListBox ListBox DropDownList Items ( ListItemCollection 類 ) SelectionMode Single Multiple ( 利 Selected true)
例 sample5-a7 (1) WebForm1.aspx private 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(); }
例 sample5-a7 (2) WebForm1.aspx private 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(); }
例 sample5-a7 (3) WebForm1.aspx private int total() { int sum = 0; foreach(listitem item in shoppinglb.items) { sum += int.parse(item.value); } return sum; }
練 sample5-b5 (1) 類 拉 說 神 龍 C# JAVA 料 料理 料理 料理
練 sample5-b5 (2) 念 拉 SelectedIndexChanged ListBox 拉 AutoPostBack true
CheckBox CheckBox Text TextAlign Checked CheckedChanged 狀 ( AutoPostBack true)
CheckBoxList CheckBoxList Items ( ListItemCollection 類 ) RepeatColumns 料欄 數 RepeatDirection SelectedIndexChanged 更 ( AutoPostBack true)
RadioButton RadioButton Text TextAlign Checked GroupName CheckedChanged 狀 ( AutoPostBack true)
RadioButtonList RadioButton 來 立 Items ( ListItemCollection 類 ) RepeatColumns 料欄 數 RepeatDirection SelectedIndexChanged 更 ( AutoPostBack true)
例 sample5-a8 (1) 料 WebForm1.aspx private void submitbtn_click(object sender, System.EventArgs e) { Session.Add("name",nameTB.Text); Session.Add("sex",sex1RB.Checked?"":""); Session.Add("education", educationrbl.selecteditem.text);
例 sample5-a8 (2) WebForm1.aspx string hobby = ""; foreach(listitem item in hobbycbl.items) if(item.selected) hobby+= item.text +" "; if(hobby == "") hobby = " "; Session.Add("hobby", hobby); } Response.Redirect("WebForm2.aspx");
例 sample5-a8 (3) WebForm2.aspx private void Page_Load(object sender, System.EventArgs e) { Response.Write(Session["name"].ToString()); Response.Write(Session["sex"].ToString() + "!!<br>"); Response.Write(" 歷 "+Session["education"].ToString() + "<br>"); Response.Write(" "+Session["hobby"].ToString()); }
練 sample5-b6 念 ListItem Value