2

記事閲覧用のWebアプリを作っています。

Edit特定のボタンがクリックされた場合にtrueに設定されるboolプロパティがあり、Saveユーザー情報を入力した後にクリックされるボタンTextBoxesやその他のコントロールもあります。アプリケーションを実行して情報を入力すると、正常に動作しますが、4 回または 5 回実行すると(アプリケーションを再起動すると)、Saveボタン をクリックすると例外エラーが発生します。 .Input string was not in a correct formatTextBoxes

私の問題は、bool プロパティ ( Managment.IsEditing) が理由もなく true に設定されていることです ( Editbool を true に設定するには、ボタンを押す必要があります)。そのコードはEditButton_Clickイベントでのみ呼び出されているため、自動的に true に設定される理由と方法は?

ここにコードがあります

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

ご不便をおかけして申し訳ありません。

4

1 に答える 1

1

指定された行で例外が発生すると、フラグをリセットする行は実行されません。その場合、ページは無効な状態になる可能性があります。

エラーを修正/処理し、適切にクリーンアップしてみてください。問題が解決する可能性があります。

于 2012-06-17T11:00:41.273 に答える