3. 댓글 입출력 폼의 처리를 담당하는 BoardCommentControl.ascx.cs 파일은 다음과 같이 코드를 작성한다.

    ▼  ~/DotNetNote/Controls/BoardCommentControl.ascx.cs

    using DotNetNote.Models;
    using System;
    
    namespace MemoEngine.DotNetNote.Controls
    {
      public partial class BoardCommentControl : System.Web.UI.UserControl
      {
          // 리파지터리 개체 생성
          private NoteCommentRepository _repository;
          
          public BoardCommentControl()
          {
              _repository = new NoteCommentRepository();
          }
          
          protected void Page_Load(object sender, EventArgs e)
          {
              if (!Page.IsPostBack)
              {
                  // 데이터 출력(현재 게시글의 번호(Id)에 해당하는 댓글 리스트)
                  ctlCommentList.DataSource =
                  _repository.GetNoteComments(Convert.ToInt32(Request[“Id”]));
                  ctlCommentList.DataBind();
              }
          }
          
          protected void btnWriteComment_Click(object sender, EventArgs e)
          {
              NoteComment comment = new NoteComment();
              comment.BoardId = Convert.ToInt32(Request[“Id”]); // 부모글
              comment.Name = txtName.Text; // 이름
              comment.Password = txtPassword.Text; // 암호
              comment.Opinion = txtOpinion.Text; // 댓글
              
              // 데이터 입력
              _repository.AddNoteComment(comment);
              
              Response.Redirect(
                  $”{Request.ServerVariables[”SCRIPT_NAME”]}?Id={Request[”Id”]}”);
          }
      }
    }
    

    신간 소식 구독하기
    뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.