2012-06-17 33 views
2

我正在制作一个用于阅读文章的Web应用程序。Bool属性被设置为true而不被称为

我如果被点击的具体Edit按钮被设置为true布尔属性,也有一个按钮Save被填充上TextBoxes和其他控件的用户信息后点击。每当我运行我的应用程序并填写信息时,它运行良好,但运行4或5次(重新启动应用程序)后,它会在单击Save按钮时产生异常错误: Input string was not in a correct format这是因为填充TextBoxes而导致Null(首先,转换成Int)。

我的问题是,布尔属性(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); 

和遗憾的任何不便亲爱研究员

+3

请给我们的问题的代码。 – Aristos

+0

代码请 –

+0

告诉我们一些代码请 –

回答

1

行,重置您的标志的行将不会运行。该页面可能会处于无效状态。

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

+0

我使用Try catch来处理异常,它不会让我的应用程序崩溃,但它不能解决我的问题。当你悲伤的是重置标志的行不会运行......所以我的问题是,为什么这个标志被转换为真,而不被调用。 (此标志在“EditButoon_Click”事件中变为真) –

+0

我非常仔细地编辑我的帖子并尽力解释。我请求再读一遍。非常感谢! –