【发布时间】:2012-06-19 16:01:54
【问题描述】:
我正在制作一个用于阅读文章的网络应用程序。
如果单击特定的Edit 按钮,我有设置为true 的bool 属性,还有一个Save 按钮,在填写TextBoxes 和其他控件的用户信息后单击。每当我运行我的应用程序并填写信息时,它运行良好,但在运行 4 或 5 次(重新启动应用程序)后,单击 Save 按钮时会出现异常错误:
Input string was not in a correct format 这是由于用 Null 填充 TextBoxes(首先将 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);
给各位小伙伴带来不便深表歉意
【问题讨论】:
-
请给我们问题的代码。
-
请给我们一些代码
-
为什么初学者被否决,给他们一些时间来学习 SO 环境!
-
计算机不只是在搞砸你,这里只有两种可能性:要么你有代码导致点击该按钮(客户端脚本可能模拟点击?)或者有在代码中调用 EditButton_Click 方法(或设置属性)的位置。
-
“运行 4 或 5 次后”是什么意思?什么是跑步?是否运行单击编辑然后保存?还是运行实际启动了应用程序?
标签: c# asp.net visual-studio-2010 boolean