2013-11-04 1 views
0

aspx 페이지에 asp FileUpload 컨트롤이 있습니다. FileUpLoads의 확장자가 허용되지 않을 때 경고 표시

그리고 뒤에있는 코드 파일의 확장자를 확인하고 데이터베이스에 삽입하기 : 위의 코드와

private string Write(HttpPostedFile file, string table) 
    { 
     string fileNameMain = Path.GetFileName(file.FileName); 

     // check for the valid file extension 
     string fileExtension = Path.GetExtension(fileNameMain).ToLower(); 
     if (fileExtension.Equals(".pdf") || fileExtension.Equals(".doc")) 
     { 
      ...insert fileupload into database 
     } 
     else 
     { 
      LabelError.Text = "Extension of files are not allowed."; 
      return null; 
     } 
    } 

, 그것은 확장을 확인하고 파일 업로드가 허가되어 있지 않은 경우 다음 LabelError에 메시지 "Extension of files are not allowed."을 보여 .

이제 다른 방법으로 "check-extension"을 수행해야합니다. 클라이언트가 클릭하여 FileUpload를 선택하면 alert이 "Extension of files are not allowed."으로 표시됩니다.

FileUpload가 브라우저에서 선택한 시간에 경고를 표시하는 방법이 필요합니다. 도움!!!!

답변

0

안녕하세요.하지만 경고 (자바 스크립트)를 원하지만 우선 code vb를 실행하기위한 다시 게시 작업이 필요하고 경고를 사용하는 경우 버튼을 사용하여이 메소드를 실행할 수 있습니다. 이 코드로 경고를 보여줄 수 있습니다.

string script = "alert('Extension of files are not allowed');"; 

ScriptManager.RegisterStartupScript(this, typeof(Page), "alert", script , true); 
관련 문제