设计一个包含两个页面的ASP.NET网站,在A页面中添加3个命令按钮控件,
不懂再问
1、response
A:页面: Response.Redirect("A.aspx?var1="+value1 & var2="+value2);
B:页面: string var1 = Request.QueryString["var1"];
string var2 = Request.QueryString["var2"];
2、session
A:页面: Session["var1"]=var1value;
Session["var2"]=var2value;
B:页面: string var1 = Session["var1"];
string var2 = Session["var2"];
3、cookie
A:页面: WriteCookie(var1,var1value);
WriteCookie(var2,var2value);
B:页面: string var1 = ReaderCookie("var1");
string var2 = ReaderCookie("var2");
/// <summary>
/// 写cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <param name="strValue">值</param>
public static void WriteCookie(string strName, string strValue)
{
HttpCookie cookie = HttpContext.Current.Request.Cookies[strName];
if (cookie == null)
{
cookie = new HttpCookie(strName);
}
cookie.Value = strValue;
HttpContext.Current.Response.AppendCookie(cookie);
}
/// <summary>
/// 读cookie值
/// </summary>
/// <param name="strName">名称</param>
/// <returns>cookie值</returns>
public static string ReaderCookie(string strName)
{
if (HttpContext.Current.Request.Cookies != null && HttpContext.Current.Request.Cookies[strName] != null)
return HttpContext.Current.Request.Cookies[strName].Value.ToString();
return "";
}
2014-04-23
a页面,b页面
传参:
a页面中传 Request.Redirect(a.页面?变量1=var1+变量2=var2);
b页面 string name1 = Request.QueryString["变量1"];//这样可以得到参数值
string name2 = Request.QueryString["变量2"];
2.a页面 Session["user"] = "honge";
Request.Redirect("Default2.aspx");
string name = Session["user"];//这样可以得到参数值
cooki不提倡,如要用,跟session同理