11.代 :從列表控件中移除項(xiàng) (Visual C#) ListBox1.Items.Remove("Mary"); 編譯代 -----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并執(zhí)行以下操作:
if (Page.IsPostBack) { System.IO.StringReader sr = new System.IO.StringReader((string)(ViewState["dSet"])); dSet.ReadXml(sr); } 編譯代 ----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并執(zhí)行以下操作:
本示例使用 HttpResponse.Redirect 方法將瀏覽器重定向到指定的 URL。 示例: Response.Redirect(http://www.microsoft.com/china); 編譯代 -----》啟動(dòng)新的 ASP.NET 應(yīng)用程序并將代 粘貼到 Page_Load 方法中。 14.代 :重定向到同一應(yīng)用程序中的其他頁(yè) (Visual C#) Server.Transfer("WebForm2.aspx"); 編譯代
本示例使用 HttpApplicationState 類保存全局信息。 示例: Application["Message"] = "AppMsg"; Application["AppStartTime"] = DateTime.Now; 編譯代 -----》啟動(dòng)新的 ASP.NET 應(yīng)用程序并將代 粘貼到 Page_Load 方法中。 16.代 :使用會(huì)話狀態(tài)保存值 (Visual C#) 本示例使用 Session.Add 方法在單個(gè)會(huì)話內(nèi)保持值。 示例: string firstName = "Jeff"; string lastName = "Smith"; string city = "Seattle"; Session.Add("First", firstName); Session.Add("Last", lastName); Session.Add("City", city); 編譯代 -----》啟動(dòng)新的 ASP.NET 應(yīng)用程序并將代 粘貼到 Page_Load 方法中。 17.代 :將數(shù)據(jù)集保存到視圖狀態(tài)中 (Visual C#) sqlDataAdapter1.Fill(dSet); System.IO.StringWriter sw = new System.IO.StringWriter(); // Write the DataSet to the ViewState property. dSet.WriteXml(sw); ViewState["dSet"] = sw.ToString(); 編譯代 -----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并執(zhí)行以下操作:
本示例將字符串值 ViewState["color"] = "yellow"; 編譯代 -----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并將代 粘貼到 Page_Load 方法中。 19.代 :選擇列表控件中的項(xiàng) (Visual C#) ListBox1.SelectedIndex = ListBox1.Items.IndexOf(ListBox1.Items.FindByText("ValueToFind")); 編譯代 -----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并執(zhí)行以下操作:
下面的示例將使用 HttpCookie 類及其屬性編寫一個(gè)一分鐘后將失效的 Cookie。 示例 HttpCookie myCookie = new HttpCookie("MyTestCookie"); DateTime now = DateTime.Now; // Set the cookie value. myCookie.Value = now.ToString(); // Set the cookie expiration date. myCookie.Expires = now.AddMinutes(1); // Add the cookie. Response.Cookies.Add(myCookie); Response.Write(" 編譯代 -----》啟動(dòng)新的 ASP.NET Web 應(yīng)用程序并將代 粘貼到 Page_Load 方法中。 來(lái)源:http://msdn.microsoft.com/zh-cn/library/aa287564(VS.71).aspx |
|
來(lái)自: 悟靜 > 《.net和asp.net》