2011-04-14 4 views
1

사용자 컨트롤 서버 측 방법에서 자바 스크립트를 호출 :ASP.Net - 나는 공공 방법으로 사용자가 제어 할 수 있습니다

public void ShowDetails(Guid requestGuid) 
    {    
     Label1.Text = reportGuid.ToString(); //only for testing    

     ScriptManager.RegisterStartupScript(UpdatePanel1, UpdatePanel1.GetType(), "ShowEmailPreview", "alert('hi');", true); 
     //ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work 
     //Page.ClientScript.RegisterStartupScript(this.GetType(), "ShowEmailPreview", "alert('hi');", true); //doesn't work 
    } 

) (이 사용자 제어 통화 ShowDetails 페이지를 호스팅, 나는 약간의 자바 스크립트를 호출 할 필요가 .

ScriptManager.RegisterStartupScript 및 Page.ClientScript.RegisterStartupScript를 시도했지만 작동하지 않습니다. 그러나 위의 그림과 같이 UpdatePanel을 내 컨트롤에 추가하고 UpdatePanel 용 스크립트를 추가하면 올바르게 작동합니다.

javascript를 호출하기 위해 UpdatePanel을 제 컨트롤에 추가하고 싶지 않습니다.

내가 누락 된 항목이 있습니까?

감사합니다.

답변

8

실제로 다음과 같이 코드를 변경하면 효과가 있습니다.

ScriptManager.RegisterStartupScript(this.Page, typeof(System.Web.UI.Page), "ShowEmailPreview", "alert('hi');", true); 
+0

최고, 감사합니다 :) – iniki

+1

이 솔루션은 내 주 변경 짧은 버전입니다. – Kulingar

0
ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "ScriptName", "alert('hi');", true); 

관련 문제