天天看點

if (! IsPostBack) { } 的使用

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

try

{

string cmdText = "select DepartmentName,DepartmentPinYin,DepartmentRemark from tb_Department where DepartmentID='" + Request["DepartmentID"] + "'";

DataSet ds = SqlHelper.Query(cmdText);

if (ds.Tables[0].Rows.Count != 0)

{

txtDepartmentName.Text = ds.Tables[0].Rows[0]["DepartmentName"].ToString();

txtDepartmentPinYin.Text = ds.Tables[0].Rows[0]["DepartmentPinYin"].ToString();

txtDepartmentRemark.Text = ds.Tables[0].Rows[0]["DepartmentRemark"].ToString();

}

}

catch (Exception ex)

{

Response.Write(ex.ToString());

}

}

}

如果沒有IsPostBack,點選确定修改按鈕,Page_Load事件會重新加載,txtDepartment**.Text會被重新還原,txtDepartment**.Text修改後的值擷取不到。