2010-03-29 3 views
4

서버 쪽에서 정적 수신 콜백 결과 메서드를 사용하여 서버 쪽에서 개체를 가져올 수 있습니다.클라이언트 쪽 함수로 서버 쪽에서 정적이 아닌 메서드 호출

하지만 내 페이지에서 클라이언트 측 함수를 호출하여 아약스 아코디언을 채우는 비 정적 메서드를 실행하고 싶습니다.

서버 측에서 호출하는 객체는 callbackresults로 얻으면 클라이언트 측에서 사용할 수없는 복잡한 객체입니다.

클라이언트 쪽 컨트롤에 의해 aspx 파일에서 비 정적 메서드를 실행할 수있는 다른 솔루션이 있습니까? 내가 지금까지 사용하고

코드 ...

 function ReceiveServerData(arg, context) { 
    //Message.innerText = "Date from server: " + arg; 
} 

#region ICallbackEventHandler Members 

public void RaiseCallbackEvent(String eventArgument) 
{ 
    // Processes a callback event on the server using the event 
    // argument from the client. 
    Insert(); // this is running, but doesnt work ! 
    //printAlternativesFromAirport(eventArgument); 
} 

public string GetCallbackResult() 
{ 
    // Returns the results of a callback event to the client. 
return null; 
} 

#endregion 


protected void Page_Load(object sender, EventArgs e) 
{ 
    ClientScriptManager cm = Page.ClientScript; 
    String cbReference = cm.GetCallbackEventReference(this, "arg", 
     "ReceiveServerData", ""); 
    String callbackScript = "function CallServer(arg, context) {" + 
     cbReference + "; }"; 
    cm.RegisterClientScriptBlock(this.GetType(), 
     "CallServer", callbackScript, true); 
} 

답변

0

그래, 당신이, 요법 전체 페이지 수명주기를 실행할 페이지에 필요한 전체 컨텍스트를 생성하는 핸들러를 작성해야하고 사용자 컨트롤이나 큰 것을 검색하고자 할 때 더 좋습니다.

public void ProcessRequest(HttpContext context) 
    { 
     context.Response.Write(RenderView("~/_controltemplates/15/myDir/Templates/myUC.ascx")); 
    } 

    public static string RenderView(string path) 
    { 
     try 
     { 
      Page pageHolder = new Page(); 
      UserControl viewControl = (UserControl)pageHolder.LoadControl(path); 
      pageHolder.Controls.Add(viewControl); 
      StringWriter result = new StringWriter(); 
      Log.Application.Debug(LOGPREFIX + "RenderView before Execute"); 
      HttpContext.Current.Server.Execute(pageHolder, result, true); 
      return result.ToString(); 
     } 
     catch (Exception ex) 
     { 
      Log.Application.ErrorException(LOGPREFIX, ex); 
      throw; 
     } 
    } 

하지만 내가 대신 내가 어떤 HttpContext를 필요 간단한 처리기에서 실행하지 않을 것이다 삽입 기능을 처리하기 위해 엔티티 (클래스)를 만들기 위해 당신을 조언 것, 당신이 무엇을 필요는 없다라고 생각합니다.

아마도 모든 포스트 백 정보가 필요하지만 전체 포스트 백을 만들고 싶지 않기 때문에 AjaxPanel을 사용하거나 응답을 지우고 대신 "확인"을 보내면되므로 다른 해결책이 필요할 수 있습니다.

관련 문제