C# Bool属性设置为true而不被调用

C# Bool属性设置为true而不被调用,c#,asp.net,visual-studio-2010,boolean,C#,Asp.net,Visual Studio 2010,Boolean,我正在制作一个用于阅读文章的web应用程序 我有一个bool属性,如果单击了特定的编辑按钮,该属性将设置为true,还有一个保存按钮,在文本框和其他控件上填充用户信息后单击该按钮。每当我运行应用程序并填写信息时,它都会正常运行,但在运行4或5次(重新启动应用程序)后,单击Save按钮时会出现异常错误: 输入字符串的格式不正确,这是由于用Null填充文本框(首先,Null被转换为Int) 我的问题是bool属性(management.IsEditing)被设置为true而没有任何原因(Edit按钮

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

我有一个bool属性,如果单击了特定的
编辑
按钮,该属性将设置为true,还有一个
保存
按钮,在
文本框
和其他控件上填充用户信息后单击该按钮。每当我运行应用程序并填写信息时,它都会正常运行,但在运行4或5次(重新启动应用程序)后,单击
Save
按钮时会出现异常错误:
输入字符串的格式不正确
,这是由于用Null填充
文本框
(首先,Null被转换为Int)

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

这里有一个代码

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

对于由此带来的不便,敬请各位同事

当所示行出现异常时,重置您的标志的行将不会运行。然后,页面可能会处于无效状态


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

请给我们问题的代码。请给我们一些代码。为什么初学者被否决,给他们一些时间学习SO环境!计算机不仅仅是在和你捣乱,这里只有两种可能性:要么你有导致该按钮点击的代码(客户端脚本可能模拟点击?),要么你在代码中有一个地方调用EditButton\u click方法(或设置属性)。你说的“运行4或5次后”是什么意思?什么是跑步?是否正在运行单击编辑然后保存?或者运行实际上是在启动应用程序?我使用Try-catch来处理异常,它不会让我的应用程序崩溃,但并没有解决我的问题。正如你所悲伤的,重置标志的行将不会运行。。。所以我的问题是为什么这个标志在没有被调用的情况下变为true。(这个标志在“EditButoon_Click”事件中变为真)我非常仔细地编辑我的帖子,并尽力解释。我要求再读一遍。非常感谢!
editor.Editor_ID = Convert.ToInt32(EditorIDTextBox.Text);