0

我创建了一个新的事件处理程序来处理两个不同的事件。一个是用于保存新文档。另一个用于保存编辑。

我在我的 Page_load 中添加了这个:

if (Request.QueryString["ExhibitID"] != null)//new
{
    if (!IsPostBack)
    {
        ddlCaseFiles.DataSourceID = "dsCaseFiles";
        ddlCaseFiles.DataTextField = "Display";
        ddlCaseFiles.DataValueField = "FileID";
        rbByFileID.Checked = true;
        rbMyFiles.Checked = false;
        ddlCaseFiles.DataBind();
        editExhibit(int.Parse(Request.QueryString["ExhibitID"]));//new
        exhibitHeader.InnerText = "Edit Exhibit";
    }
    hidSavedExhibitID.Value = Request.QueryString["ExhibitID"];
    saveExhibitBtn.Click += new EventHandler(this.btnUpdateExhibit_Click);
}
else
{
    saveExhibitBtn.Click += new EventHandler(this.saveExhibitBtn_Click);
}

我的保存方法由于某种原因一直循环然后崩溃,因为它第二次通过,没有数据,因为我在第一次保存后重置它。我不知道为什么它会运行我的保存方法两次。

这是我的保存方法:

 protected void saveExhibitBtn_Click(object sender, EventArgs e)
{
    hidSavedExhibitID.Value = null;
    int newExhibitID = saveExhibit();

    int propertyID = autoCreateProperty(newExhibitID);
    linkExhibitAndProperty(newExhibitID, propertyID);

    SaveInfoIntoSessionVariables();
    ClearFormFields();
}

“saveExhibit()”方法是我实际访问数据库并存储所有内容的地方。它工作正常。

4

1 回答 1

2

Because you re bind your datas in your Page_Load.

You must persist your datas with ViewState, EnableViewState="true"

You bind your datas just one time, in the ! IsPostBack. in order to not erase the selected values

If(! IsPostBack)
{

   //Bind your datas with `DataBind()`
}
于 2012-09-25T18:51:48.470 回答