2

我正在制作一个用于阅读文章的网络应用程序。

如果单击特定按钮,我将 bool 属性设置为 true Edit,还有一个SaveButton 在填充用户信息TextBoxes和其他控件后单击。每当我运行我的应用程序并填写信息时,它运行良好,但在运行 4 或 5 次(重新启动应用程序)后,单击SaveButton 时会出现异常错误: Input string was not in a correct format这是由于填充TextBoxesNull(首先,Null 转换为 Int) .

我的问题是 bool 属性 ( Managment.IsEditing) 无任何理由设置为 true (Edit应按下按钮将 bool 设置为 true)。为什么以及如何自动设置为 true,因为它的代码只在EditButton_ClickEvent 中被调用?

这是一个代码

protected void EditButton_Click(object sender, EventArgs e)
{
    if(EditorList.SelectedIndex > -1) //Just to ensure that Item is selected from ListBox
    {   
        //editor is the poco  , EditorManager is the editor table manager
        editor = EditorManager.GetEditorInfo(EditorList.SelectedValue);

        NameTextBox.Text = editor.Name;
        EmailTextBox1.Text = editor.Email;
        PasswordTextBox.Text = editor.Password;
        EditorIDTextBox.Text = editor.Editor_ID.ToString();

        for (int index = 0; index < RoleCheckBoxList.Items.Count; index++)
        {
          RoleCheckBoxList.Items[index].Selected = editor.RoleList[index];
        }

        Managment.IsEditing = true; //This flag is responsible for telling "SaveButtton" that editor would be updated. 
        DeleteButton.Enabled = true;
        ResultLabel.Text = "";
    }

    else
        ResultLabel.Text = "Select Editor from list first";

protected void SaveButton_Click(object sender, EventArgs e)
{
    if(Managment.IsEditing == false) //it makes sure that new editor is being saved
    {
        editor.Name = NameTextBox.Text;
        string email = EmailTextBox1.Text;
        editor.Email = email.ToLower();
        editor.Password = PasswordTextBox.Text;

        if(EditorManager.IsEditorValid(editor.Email))
        {
            for (int index = 0; index < RoleCheckBoxList.Items.Count; index++)
            {
              editor.RoleList[index] = RoleCheckBoxList.Items[index].Selected;
            }

            EditorManager.Save(editor);
            ResultLabel.Text = editor.DataUploadMessage;            
        }

        else
            ResultLabel.Text = "Editor with the same Email can't be add!";

        FillEditorList();
    }

    else if(Managment.IsEditing == true) //it determines that existing editor is being updated and problem is that Managment.IsEditing is turned on without being called.
    {
        editor.Name = NameTextBox.Text;
        string email = EmailTextBox1.Text;
        editor.Email = email.ToLower();
        editor.Password = PasswordTextBox.Text;
        editor.Editor_ID = Convert.ToInt32(EditorIDTextBox.Text);// Error occurs at this line

        for (int index = 0; index < RoleCheckBoxList.Items.Count; index++)
        {
          editor.RoleList[index] = RoleCheckBoxList.Items[index].Selected;
        }

        EditorManager.Edit(editor);

        ResultLabel.Text = editor.DataUploadMessage;
        Managment.IsEditing = false;
        FillEditorList();            
    }
    ClearFields(Form.Controls);
}

该行发生异常:

editor.Editor_ID = Convert.ToInt32(EditorIDTextBox.Text);

亲爱的朋友们,抱歉给您带来不便

4

1 回答 1

1

当指定行发生异常时,将不会运行重置标志的行。该页面可能会处于无效状态。

尝试修复/处理错误并正确清理,问题可能会消失。

于 2012-06-17T11:00:41.273 回答