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

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

我的问题是bool属性(Managment.IsEditing)设置为true没有任何原因(应按下Edit按钮将bool设置为true)。为什么以及如何自动将其设置为true,因为仅在EditButton_Click事件中调用其代码?

这是一个代码

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);


对于给您带来的不便深表歉意

最佳答案

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

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

关于c# - Bool属性设置为true而不被调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11070060/

10-10 23:33