1. IsPostBack的官方解释:
获取一个值,该值指示页是第一次呈现还是为了响应回发而加载。
如果是为响应客户端回发而加载该页,则为 true;否则为 false。
2. 做如下试验:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtHidden.Value = "!IsPostBack";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script type='text/javascript'>alert('" + this.txtHidden.Value + "');</script>");
}
结果:!IsPostBack
稍作改动
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtHidden.Value = "!IsPostBack";
}
else
{
this.txtHidden.Value = "IsPostBack";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<script type='text/javascript'>alert('" + this.txtHidden.Value + "');</script>");
}
结果:IsPostBack
这里说明,如果需要在页面加载时给控件赋值,在!IsPostBack中进行;
由页面逻辑操作改变控件的值,可以在IsPostBack中进行。
未完待续…