11.代 :从列表控件中移除项 (Visual C#) ListBox1.Items.Remove("Mary"); 编译代 -----》启动新的 ASP.NET Web 应用程序并执行以下操作:
if (Page.IsPostBack) { System.IO.StringReader sr = new System.IO.StringReader((string)(ViewState["dSet"])); dSet.ReadXml(sr); } 编译代 ----》启动新的 ASP.NET Web 应用程序并执行以下操作:
本示例使用 HttpResponse.Redirect 方法将浏览器重定向到指定的 URL。 示例: Response.Redirect(http://www.microsoft.com/china); 编译代 -----》启动新的 ASP.NET 应用程序并将代 粘贴到 Page_Load 方法中。 14.代 :重定向到同一应用程序中的其他页 (Visual C#) Server.Transfer("WebForm2.aspx"); 编译代
本示例使用 HttpApplicationState 类保存全局信息。 示例: Application["Message"] = "AppMsg"; Application["AppStartTime"] = DateTime.Now; 编译代 -----》启动新的 ASP.NET 应用程序并将代 粘贴到 Page_Load 方法中。 16.代 :使用会话状态保存值 (Visual C#) 本示例使用 Session.Add 方法在单个会话内保持值。 示例: string firstName = "Jeff"; string lastName = "Smith"; string city = "Seattle"; Session.Add("First", firstName); Session.Add("Last", lastName); Session.Add("City", city); 编译代 -----》启动新的 ASP.NET 应用程序并将代 粘贴到 Page_Load 方法中。 17.代 :将数据集保存到视图状态中 (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(); 编译代 -----》启动新的 ASP.NET Web 应用程序并执行以下操作:
本示例将字符串值 ViewState["color"] = "yellow"; 编译代 -----》启动新的 ASP.NET Web 应用程序并将代 粘贴到 Page_Load 方法中。 19.代 :选择列表控件中的项 (Visual C#) ListBox1.SelectedIndex = ListBox1.Items.IndexOf(ListBox1.Items.FindByText("ValueToFind")); 编译代 -----》启动新的 ASP.NET Web 应用程序并执行以下操作:
下面的示例将使用 HttpCookie 类及其属性编写一个一分钟后将失效的 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(" 编译代 -----》启动新的 ASP.NET Web 应用程序并将代 粘贴到 Page_Load 方法中。 来源:http://msdn.microsoft.com/zh-cn/library/aa287564(VS.71).aspx |
|
来自: 悟静 > 《.net和asp.net》