2012-10-24 3 views
0

내 코드에 어떤 문제가 있습니까? Visual Studio에는 경고 나 오류가 표시되지 않습니다.오류 렌더링 제어 - WebUserControl, 처리되지 않은 예외가 발생했습니다.

ASP.NET, 오류 렌더링 컨트롤 - WebUserControl, 처리되지 않은 예외가 발생했습니다. 웹 브라우저에서

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs"   Inherits="WebUserControl" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<script runat="server"> 

    protected void UploadButton_Click(object sender, EventArgs e) 
    { 
     // Specify the path on the server to 
     // save the uploaded file to. 
     String savePath = @"c:\temp\uploads\"; 

     // Before attempting to perform operations 
     // on the file, verify that the FileUpload 
     // control contains a file. 
     if (FileUpload1.HasFile) 
     { 
      // Get the name of the file to upload. 
      String fileName = FileUpload1.FileName; 

      // Append the name of the file to upload to the path. 
      savePath += fileName; 


      // Call the SaveAs method to save the 
      // uploaded file to the specified path. 
      // This example does not perform all 
      // the necessary error checking.    
      // If a file with the same name 
      // already exists in the specified path, 
      // the uploaded file overwrites it. 
      FileUpload1.SaveAs(savePath); 

      // Notify the user of the name of the file 
      // was saved under. 
      UploadStatusLabel.Text = "Your file was saved as " + fileName; 
     } 
     else 
     { 
      // Notify the user that a file was not uploaded. 
      UploadStatusLabel.Text = "You did not specify a file to upload."; 
     } 

    } 

</script> 

<html > 
<head id="Head1" runat="server"> 
    <title>FileUpload Example</title> 
    <style type="text/css"> 
     .style1 
     { 
      width: 100%; 
     } 
     .style2 
     { 
      height: 26px; 
     } 
    </style> 
</head> 
<body> 
    <form id="form1" runat="server"> 
    <table class="style1"> 
     <tr> 
      <td> 
       Select a file to upload:</td> 
      <td> 
       &nbsp;</td> 
     </tr> 
     <tr> 
      <td class="style2"> 

     <asp:FileUpload id="FileUpload1"     
      runat="server"> 
     </asp:FileUpload> 

      </td> 
      <td class="style2"> 
      </td> 
     </tr> 
     <tr> 
      <td> 

     <asp:Button id="UploadButton" 
      Text="Upload file" 
      OnClick="UploadButton_Click" 
      runat="server"> 
     </asp:Button>  

      </td> 
      <td> 
       &nbsp;</td> 
     </tr> 
     <tr> 
      <td> 

     <hr /> 

      </td> 
      <td> 
       &nbsp;</td> 
     </tr> 
     <tr> 
      <td> 

     <asp:Label id="UploadStatusLabel" 
      runat="server"> 
     </asp:Label>   
      </td> 
      <td> 
       &nbsp;</td> 
     </tr> 
    </table> 
    </form> 
    <p> 
     &nbsp;</p> 
</body> 
</html> 

오류 메시지 : 당신은 당신의 선언을 교체해야

Server Error in '/WebSite2' Application. 
-------------------------------------------------------------------------------- 

You can only have one <head runat="server"> control on a page. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Web.HttpException: You can only have one <head runat="server"> control on a page. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[HttpException (0x80004005): You can only have one <head runat="server"> control on a page.] 
    System.Web.UI.HtmlControls.HtmlHead.OnInit(EventArgs e) +1762795 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +333 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.AddedControl(Control control, Int32 index) +198 
    System.Web.UI.ControlCollection.Add(Control child) +80 
    System.Web.UI.WebControls.WebParts.WebPartManagerControlCollection.AddWebPartHelper(WebPart webPart) +220 
    System.Web.UI.WebControls.WebParts.WebPartManagerControlCollection.AddWebPartsFromZone(WebPartZoneBase zone, WebPartCollection webParts) +607 
    System.Web.UI.WebControls.WebParts.WebPartManager.RegisterZone(WebZone zone) +240 
    System.Web.UI.WebControls.WebParts.WebZone.OnInit(EventArgs e) +95 
    System.Web.UI.WebControls.WebParts.WebPartZone.OnInit(EventArgs e) +9 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +333 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Control.InitRecursive(Control namingContainer) +210 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +378 

답변

2

UserControl이이 페이지의 내용에 포함 따라서 그것은해서는 안

만 ....이 아니라 전체 HTML 구조 많은 HTML을 넣어 머리 부분. 실제 페이지에만 헤더가 있어야합니다.

html, 본문 등 다른 문서 섹션도 포함하면 안됩니다.

0

:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %> 

또는 당신은 정말 당신을 제거해야 사용자 지정 컨트롤을 수를 의미 html 및 head 태그

2

UserControl의 전체 HTML 구조가 있습니까? 다른 페이지에서이 컨트롤을 사용할 때마다 다른 HTML 문서 전체에 삽입됩니다. 만 .. 당신의 컨트롤을 렌더링하는 데 필요한 HTML ...이 아니라 전체 페이지

편집을 포함 나는 그 코멘트가 아닌 대답으로 더 의미를 만들었을 것입니다 말로 표현하는 방법을 생각한다. 그래서 ... 질문에 .... 당신의 컨트롤은 그것에 완전한 HTML 구조를 가지고 있습니다. 그래서 Webforms 페이지에서 사용될 때 당신은 다른 HTML 구조 안에 전체 HTML 구조를 삽입하려고합니다. 당신이 당신의 .ascx에서 컨트롤을 렌더링하는 데 필요로하는

+0

감사합니다. a bunch guys – somethingSomething