當用ajax時
這時
如果在裡面放一個要換頁的網頁
真的很麻煩
所以我選擇放一個iframe來減少資料庫的存取
但是不想要postback的狀況
決定用viewstate來處理
以下只是一小部份
但是看懂的人已經足夠了
protected override void LoadViewState(object savedState)
{
if (savedState != null)
{
object[] myState = (object[])savedState;
var listItem = (new JavaScriptSerializer()).Deserialize<ListItem[]>(myState[2].ToString());
this.ddlPage.Items.AddRange(listItem);
this.laTotal.Text = ((DataTable)myState[1]).Rows.Count.ToString();
ViewState["xx1"] = myState[1];
ViewState["xx2"] = myState[2];
}
}
protected override object SaveViewState()
{
if (IsPostBack && "1".Equals(this.ddlPage.SelectedValue) && "20".Equals(this.ddlCount.SelectedValue))
{
setTable("ddlCount");
}
return new object[]{
base.SaveViewState(),
ViewState["xx1"],
ViewState["xx2"],
this.ddlPage.SelectedValue,
this.ddlCount.SelectedValue
};
}
protected void ddlPage_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
setTable(((DropDownList)sender).ID);
}
}
protected void ddlCount_SelectedIndexChanged(object sender, EventArgs e)
{
if (IsPostBack)
{
setTable(((DropDownList)sender).ID);
}
}
留言列表