2017-05-17 3 views
0

pdf 파일 목록이있는 gridview가 있습니다. 사용자가 pdf를 클릭하면 페이지에 파일이 인라인으로 표시됩니다. PDF로드 된 후 일부 자바 스크립트를 실행하려면이 작동하도록 가져올 수 없습니다. 문제는 pdf가 다른 모든 것 이후에로드되므로 pdf가로드되기 전에로드 이벤트가 시작된다는 것입니다.제네릭 처리기 asp.net을로드 한 후 javascript를 실행하십시오.

첫 번째 방법은 iframe을 사용하는 것이 었습니다. 내부 페이지는 파일을 검색하고 응답에 데이터를 씁니다. 앞서 언급했듯이로드 이벤트는 pdf를로드하기 전에 발생했으며 이후에 트리거해야합니다. 현재 코드는 pdf 인라인을로드하기 위해 일반 처리기 ashx를 사용합니다. pdf 데이터가 서버 측 ashx 제네릭 처리기에서로드 된 후 JavaScript를 실행하는 이벤트를 어떻게 트리거합니까?

aspx 페이지 :

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) 
{ 
    if (e.CommandName == "View") 
    { 
     int index = Convert.ToInt32(e.CommandArgument.ToString()); 
     string Id = GridView1.DataKeys[index].Value.ToString(); 
     HtmlGenericControl myObject = new HtmlGenericControl(); 
     myObject.TagName = "object"; 
     Panel1.Controls.Add(myObject); 
     myObject.Attributes.Add("data", "GetPdf.ashx?Id=" + Id); 
    } 
} 

일반 핸들러 ASHX :

public void ProcessRequest(HttpContext context) 
{ 
    System.Diagnostics.Debug.WriteLine("GetPdf.ashx started"); 
    string Id = context.Request.QueryString["Id"]; 
    byte[] data = GetPdf(Id); 
    context.Response.ClearContent(); 
    context.Response.ContentType = "application/pdf"; 
    context.Response.AppendHeader("Content-disposition", "inline"); 
    context.Response.AddHeader("Content-Length", data.Length.ToString()); 
    context.Response.BinaryWrite(data); 
    System.Diagnostics.Debug.WriteLine("GetPdf.ashx is done"); 
    context.Response.End(); 
} 

답변

0

당신이 object 태그의 onload 이벤트에 대한 이벤트 처리기를 설정 시도? 모든 브라우저에서 작동하는지 잘 모르겠지만 어떤 브라우저에서 작동해야하는지 알지 못합니다.

setTimeout을 사용하면 PDF 존재를 빠르게 폴링 할 수 있습니다.

Here's a previous answer 두 가지면에서 도움이 될 수 있습니다.

관련 문제