我正在为阅读文章制作一个网络应用程序。
我有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);
对于给亲们带来的任何不便表示歉意
答案 0 :(得分:1)
当指示的行发生异常时,将不会运行重置您的标志的行。然后该页面可能处于无效状态。
尝试修复/处理错误并正确清理,问题可能会消失。