2012-11-13 44 views
0

當我運行下面的代碼我正在此錯誤消息:asp.net代碼顯示編譯器錯誤消息:CS1729:「EmailReader.Pop3Client」不包含一個構造函數0參數

錯誤消息:

Compilation Error 

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1729: 'EmailReader.Pop3Client' does not contain a constructor that takes 0 arguments 

Source Error: 
Line 148:  private static object @__fileDependencies; 
Line 149: 
Line 150:  [System.Diagnostics.DebuggerNonUserCodeAttribute()] 
Line 151:  public pop3client_aspx() { 
Line 152:   string[] dependencies; 

Home.aspx.cs代碼:

protected void Button1_Click(object sender, EventArgs e) 
{ 
    Session["email"] = txt_email.Text; 
    Session["pwd"] = txt_password.Text; 
    Response.Redirect("Pop3Client.aspx"); 
} 

當我通過代碼,在Pop3Client.aspx.cs Page_Load事件斷點沒有得到執行。任何想法如何解決這個問題?

Pop3Client.aspx.cs

protected void Page_Load(object sender, EventArgs e) 
{ 

    int page = 1; 
    if (Request.QueryString["page"] == null) 
    { 
     Response.Redirect("Pop3Client.aspx?page=1"); 
     Response.Flush(); 
     Response.End(); 
    } 
    else 
     page = Convert.ToInt32(Request.QueryString["page"]); 
    try 
    { 
     Email = Session["email"].ToString(); 
     Password = Session["pwd"].ToString(); 
    } 
    catch (Exception ex) 
    { 
     Response.Redirect("Home.aspx"); 
    } 

    int totalEmails; 

    List<Email> emails; 
    string emailAddress; 
    using (EmailReader.Pop3Client client = new EmailReader.Pop3Client(Host, Port, Email, Password, true)) 
    { 
     emailAddress = client.Email; 
     client.Connect(); 
     totalEmails = client.GetEmailCount(); 
     emails = client.FetchEmailList(((page - 1) * NoOfEmailsPerPage) + 1, NoOfEmailsPerPage); 
    } 

    int totalPages; 
    int mod = totalEmails % NoOfEmailsPerPage; 
    if (mod == 0) 
     totalPages = totalEmails/NoOfEmailsPerPage; 
    else 
     totalPages = ((totalEmails - mod)/NoOfEmailsPerPage) + 1; 
    for (int i = 0; i < emails.Count; i++) 
    { 
     Email email = emails[i]; 
     int emailId = ((page - 1) * NoOfEmailsPerPage) + i + 1; 
     TableCell noCell = new TableCell(); 
     noCell.CssClass = "emails-table-cell"; 
     noCell.Text = Convert.ToString(emailId); 
     TableCell fromCell = new TableCell(); 
     fromCell.CssClass = "emails-table-cell"; 
     fromCell.Text = email.From; 
     TableCell subjectCell = new TableCell(); 
     subjectCell.CssClass = "emails-table-cell"; 
     subjectCell.Style["width"] = "300px"; 
     subjectCell.Text = String.Format(DisplayEmailLink, emailId, email.Subject); 
     TableCell dateCell = new TableCell(); 
     dateCell.CssClass = "emails-table-cell"; 
     if (email.UtcDateTime != DateTime.MinValue) 
      dateCell.Text = email.UtcDateTime.ToString(); 
     TableRow emailRow = new TableRow(); 
     emailRow.Cells.Add(noCell); 
     emailRow.Cells.Add(fromCell); 
     emailRow.Cells.Add(subjectCell); 
     emailRow.Cells.Add(dateCell); 
     EmailsTable.Rows.AddAt(2 + i, emailRow); 
    } 
    if (totalPages > 1) 
    { 
     if (page > 1) 
      PreviousPageLiteral.Text = String.Format(SelfLink, page - 1, "Previous Page"); 
     if (page > 0 && page < totalPages) 
      NextPageLiteral.Text = String.Format(SelfLink, page + 1, "Next Page"); 
    } 
    EmailFromLiteral.Text = Convert.ToString(((page - 1) * NoOfEmailsPerPage) + 1); 
    EmailToLiteral.Text = Convert.ToString(page * NoOfEmailsPerPage); 
    EmailTotalLiteral.Text = Convert.ToString(totalEmails); 
    EmailLiteral.Text = emailAddress; 
} 
+0

您可以顯示您的Pop3Client.aspx.cs的開始和Pop3Client.aspx頁面的標題嗎? – Blachshma

回答

0

的錯誤,說明你的地方有一個new EmailReader.Pop3Client()。您顯示的代碼沒有該錯誤。

所以有問題的代碼必須在別的地方。

1

您似乎已將具有參數的構造函數添加到您的Pop3Client代碼隱藏類中。這意味着你的類不再包含無參數的構造函數。 ASP.NET需要這樣的構造函數才能存在,因爲在第一次加載頁面時編譯頁面。

沒有理由在ASP.NET頁面的代碼隱藏中有一個構造函數,所以你應該把它拿出來,但是增加一個無參數的構造函數也應該可以工作。

+0

@Rawling ...我不確定你的意思。我在代碼隱藏中看不到帶有參數的構造函數。 – DotNetRookie

+0

嗯......無參數構造函數標記爲private? – Rawling

+1

@搖滾你搖滾!一年的問題,仍然挽救生命 – MrCarder

相關問題