IsPostBack:
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.username.Text = "";
this.userpwd.Text = "";
}
this.gb.Attributes.Add("onclick", "window.close()");
}
protected void dl_Click(object sender, EventArgs e)
if (username.Text == "admin" && userpwd.Text == "admin")
Response.Redirect("admin_index.aspx");
}
else
Response.Redirect("sb.aspx");
protected void qk_Click(object sender, EventArgs e)
this.username.Text = "";
this.userpwd.Text = "";
}
Request和Response:protected void Button1_Click1(object sender, EventArgs e)
int aa = int.Parse(Request.Form["pf"].ToString());
Response.Write("求平方的数是:" + aa + "<br>");
Response.Write(aa + "的平方是:" + aa * aa);
获取客户端的相关信息:string ie=Request.UserAgent;//获取客户端浏览器
string ip = Request.UserHostAddress;//换取客户端IP地址
string ser = Request.PhysicalApplicationPath;//获取当前文件服务器物理路径
Response.Write(ie+"<br>"+ip+"<br>"+ser);
----
•public partial class Default2 : System.Web.UI.Page
•{
• protected void Page_Load(object sender, EventArgs e)
• {
• Application["hygl"] = "呵呵你来了啊难的啊";
• Response.Write(Application["hygl"]); //输出
• }
•}
聊天室应用:![](https://img.laitimes.com/img/_0nNw4CM6IyYiwiM6ICdiwiIml2ZucDO2EjN3AzN2YjMyEDNxETM4ADMy8CXxEDOwAjMvwFduVWboNWY0RXYvwVbvNmLvR3YxUjL0M3Lc9CX6MHc0RHaiojIsJye.gif)
• protected void Button1_Click(object sender, EventArgs e)
• string mywords = Request["mywords "];
• Application.Lock(); //锁定
• Application["chat"] = Application["chat"] + "<br>" + mywords ;
• Response.Write(Application["chat"]);
• Application.UnLock(); //解锁
• }
网页计数器:protected void Page_Load(object sender, EventArgs e)
{
Application.Lock();
Application["count"] = Convert.ToInt32(Application["count"]) + 1; //每次加1
Application.UnLock();
Response.Write("您是本站第" + Application["count"] + "位贵宾!");// 输出你是第多少位来×××!!!
•
•protected void Page_Load(object sender, EventArgs e)
• Response.Write("传回当前文件所在的物理路径:<BR>");
• Response.Write(Server.MapPath("."));
//是不规则的编号
为每一位用户分配一个ID:
• protected void Page_Load(object sender, EventArgs e)
• Response.Write("您的随即编号为:"+Session.SessionID);
自定义属性:• Session["h"] = "欢迎!";
• Response.Write(Session["h"]);
• <div> <a href=Default3.aspx>在另外一个页面查看</a> </div>
•以上代码为页面1中代码
• Response.Write(Session["h"]);
•以上代码为页面2中代码
• Session.Timeout = 1;
• Session.Abandon();
• <div><a href=Default3.aspx>在另外一个页面查看</a></div>
Cookie对象:
•Cookie对象也可以保存客户信息,与Session 对象相似,分别保存不同用户的信息。
•和Session的区别是:Session对象所有信息保存在服务器上,Cookie对象所有信息保存在客户端的浏览器上
将信息保存到浏览器(第一步):• HttpCookie mycookie = new HttpCookie("user");
• mycookie.Value = "asp.net入门";
• Response.Cookies.Add(mycookie);
• <div> <a href=Default3.aspx>在另外一个页面查看</a> </div>
• string mycook = Request.Cookies["user"].Value;
• Response.Write(mycook);
•在新页面中实现以上代码
•
•