post表单时原来页面上的静态字段会清空么?
public partial class Admin_addMenu : System.Web.UI.Page
{
protected string id;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
id = Request.QueryString["id"];
if (id != "" && id != null)
{
getList();
this.tijiao.Value = "编辑";
DataSet ds = MenuDAL.returnGlobal(id);
ds = MenuDAL.returnGlobal(id);
this.title.Value = ds.Tables[0].Rows[0]["Title"].ToString();
this.link.Value = ds.Tables[0].Rows[0]["pageLink"].ToString();
this.menuid.Value = ds.Tables[0].Rows[0]["ID"].ToString();
this.isuse.SelectedIndex = ((ds.Tables[0].Rows[0]["isUse"].ToString().ToLower()) == "true") ? 1 : 0;
this.myDropdownlist.SelectedValue = ds.Tables[0].Rows[0]["parentID"].ToString();
}
else
{
this.tijiao.Value = "提交";
getList();
}
}
}
protected void addMenu(object sender, EventArgs e)
{
string _title = this.title.Value;
string _link = this.link.Value;
string _id = this.menuid.Value;
string _parentid = myDropdownlist.SelectedValue;
string _isUse = this.isuse.Value;
int result = (id != null && id != "") ? 1 : -1;
result = MenuDAL.isSuccess(result, _title, _link, _id, _parentid, _isUse);
if (result > 0)
{
RegisterStartupScript("提示", "<script>alert('操作成功!');location.href='WebSet.aspx'</script>");
}
else
{
RegisterStartupScript("提示", "<script>alert('操作失败!');</script>");
}
}
}
<input type="submit" value=" 编辑 " style="padding: 2px 3px" runat="server" onserverclick="addMenu"
id="tijiao" />
[解决办法]
把你的
protected string id;
改为类似这样的代码
private string id
{
get{ (string)ViewState["id"]; }
set{ ViewState["id"]=value; }
}