2011-05-16 6 views
0

JQuery AjaxUpload를 사용하여 이미지를 업로드하고 업로드 된 이미지로 이미지 컨트롤을 업데이트하려고했지만 ViewState를 설정할 수없는 경우에도 코드가 작동하지 않습니다. 나는 왜 그것이 일어나고 있는지 알고 싶다.
JQuery AjaxUpload 이후에 서버 컨트롤이 업데이트되지 않았습니다.

HttpPostedFile hpfFile = Request.Files["myfile"]; 
    if (hpfFile != null) 
    { 
     hpfFile.SaveAs(Server.MapPath("~/ajaxUpload/" + hpfFile.FileName)); 
     img.Src = Server.MapPath("~/ajaxUpload/" + hpfFile.FileName); 
    }<br> 

나를 왜 "img.Src"업데이트되지를 알려 주시기 바랍니다

**Javascript:**<br> 
<script type="text/javascript"> /*<![CDATA[*/<br> 
     $(document).ready(function() {<br> 
      /* Example 1 */<br> 
      var button = $('#button1'), interval;<br> 
      new AjaxUpload(button, {<br> 
       action: 'fileupload.aspx',<br> 
       name: 'myfile',<br> 
       onSubmit: function(file, ext) {<br> 
        // change button text, when user selects file<br> 
        button.text('Uploading');<br> 
        // If you want to allow uploading only 1 file at time,<br> 
        // you can disable upload button<br> 
        // this.disable();<br> 
        // Uploding -> Uploading. -> Uploading...<br> 
        interval = window.setInterval(function() {<br> 
         var text = button.text();<br> 
         if (text.length < 13) {<br> 
          button.text(text + '.');<br> 
         } else {<br> 
          button.text('Uploading');<br> 
         }<br> 
        }, 200);<br> 
       },<br> 
       onComplete: function(file, response) {<br> 
        button.text('Upload');<br> 
        window.clearInterval(interval);<br> 
        // enable upload button<br> 
        this.enable();<br> 
        // add file to the list<br> 
        $('<li></li>').appendTo('#example1 .files').text(file);<br> 
//     document.getElementById('img').src = 'C:\\Documents and <br>Settings\\Kavita\\My Documents\\Visual Studio 2008\\WebSites\\WebSite2\\ajaxUpload\\' + file;<br> 
//     alert(document.getElementById('img').src);<br> 
       }<br> 
      });<br> 
     }); /*]]>*/</script><br><br> 

fileupload.aspx.cs 코드 : 아래 코드?

답변

1

img.Src는 서버 측에서 업데이트 중이지만 Ajax 호출을하면 클라이언트 측에 다시 전송되지 않습니다.

이미지를 표시하려면 onComplete jQuery 함수에서 완료해야합니다.이 코드는 이미지가 완전히 업로드되었을 때 클라이언트 측에서 실행됩니다.

또한 서버 방법에 오류가 있음을 알았습니다. Server.MapPath을 사용하여 이미지 소스를 설정했습니다. 이는 이미지의 서버 경로 (예 : "C : \ inetpub ...")를 보내기 때문에 잘못되었거나, 다음과 같이 값을 설정해야합니다.

img.Src = "~/ajaxUpload/" + hpfFile.FileName; 
관련 문제