2010-05-11 3 views
1

NumericUpDownExtender를 캡슐화하는 사용자 정의 컨트롤이 있습니다. 이 UserControl은 ICallbackEventHandler 인터페이스를 구현합니다. 사용자가 서버에서 발생시킬 사용자 지정 이벤트와 관련된 텍스트 상자의 값을 변경할 때 필요하기 때문입니다. 반면에 비동기 포스트 백이 수행 될 때마다 전체 화면로드 및 비활성화 메시지가 표시됩니다. 뭔가 코드의 라인을 통해 예를 들어 UpdatePanel을에서 변경 될 때이 완벽하게 작동합니다.Ajax, 콜백, 포스트 백 및 Sys.WebForms.PageRequestManager.getInstance(). add_beginRequest

Sys.WebForms.PageRequestManager.getInstance() add_beginRequest ( 기능 (보낸 사람, 인수) { VAR modalPopupBehavior = $ 찾기 (' 프로그래밍 방식의 SaveLoadingModalPopupBehavior '); modalPopupBehavior.show(); } );

UserControl은 aspx의 UpdatePanel 내부에있는 detailsview 내부에 배치됩니다. 사용자 지정 이벤트가 발생하면 aspx의 다른 텍스트 상자에서 해당 값을 변경합니다. 지금까지 UpDownExtender를 클릭하면 서버로 올바르게 이동하고 사용자 지정 이벤트가 발생하고 서버의 텍스트 상자에 새 값이 할당됩니다. 브라우저에서는 변경되지 않습니다.

IPostbackEventHandler를 구현하는 AutoCompleteExtender가있는 UserControl과 동일한 아키텍처를 갖고 있기 때문에이 문제가 콜백으로 의심됩니다. 실마리처럼 작동하도록 UpDownNumericExtender 사용자 컨트롤을 만들기 위해 여기에서 어떻게 해결할 수 있습니까?

using System; 
using System.Web.UI; 
using System.ComponentModel; 
using System.Text; 

namespace Corp.UserControls 
{ 
    [Themeable(true)] 
    public partial class CustomNumericUpDown : CorpNumericUpDown, ICallbackEventHandler 
    { 
     protected void Page_PreRender(object sender, EventArgs e) 
     { 
      if (!Page.IsPostBack) 
      { 
       currentInstanceNumber = CorpAjaxControlToolkitUserControl.getNextInstanceNumber(); 
      } 
      registerControl(this.HFNumericUpDown.ClientID, currentInstanceNumber); 
      string strCallServer = "NumericUpDownCallServer" + currentInstanceNumber.ToString(); 

      // If this function is not written the callback to get the disponibilidadCliente doesn't work 
      if (!Page.ClientScript.IsClientScriptBlockRegistered("ReceiveServerDataNumericUpDown")) 
      { 
       StringBuilder str = new StringBuilder(); 
       str.Append("function ReceiveServerDataNumericUpDown(arg, context) {}").AppendLine(); 
       Page.ClientScript.RegisterClientScriptBlock(typeof(CorpNumericUpDown), 
                  "ReceiveServerDataNumericUpDown", str.ToString(), true); 
      } 

      nudeNumericUpDownExtender.BehaviorID = "NumericUpDownEx" + currentInstanceNumber.ToString(); 
      ClientScriptManager cm = Page.ClientScript; 
      String cbReference = cm.GetCallbackEventReference(this, "arg", "ReceiveServerDataNumericUpDown", ""); 
      String callbackScript = "function " + strCallServer + "(arg, context)" + Environment.NewLine + "{" + Environment.NewLine + cbReference + ";" + Environment.NewLine + "}" + Environment.NewLine; 
      cm.RegisterClientScriptBlock(typeof(CustomNumericUpDown), strCallServer, callbackScript, true); 
      base.Page_PreRender(sender,e); 
     } 

     [System.ComponentModel.Browsable(true)] 
     [System.ComponentModel.Bindable(true)] 
     public Int64 Value 
     { 
      get { return (string.IsNullOrEmpty(HFNumericUpDown.Value) ? Int64.Parse("1") : Int64.Parse(HFNumericUpDown.Value)); } 
      set 
      { 
       HFNumericUpDown.Value = value.ToString(); 
       //txtAutoCompleteCliente_AutoCompleteExtender.ContextKey = value.ToString(); 
       // TODO: Change the text of the textbox 
      } 
     } 

     [System.ComponentModel.Browsable(true)] 
     [System.ComponentModel.Bindable(true)] 
     [Description("The text of the numeric up down")] 
     public string Text 
     { 
      get { return txtNumericUpDown.Text; } 
      set { txtNumericUpDown.Text = value; } 
     } 

     public delegate void NumericUpDownChangedHandler(object sender, NumericUpDownChangedArgs e); 
     public event NumericUpDownChangedHandler numericUpDownEvent; 

     [System.ComponentModel.Browsable(true)] 
     [System.ComponentModel.Bindable(true)] 
     [System.ComponentModel.Description("Raised after the number has been increased or decreased")] 
     protected virtual void OnNumericUpDownEvent(object sender, NumericUpDownChangedArgs e) 
     { 
      if (numericUpDownEvent != null) //check to see if anyone has attached to the event 
       numericUpDownEvent(this, e); 
     } 

     #region ICallbackEventHandler Members 

     public string GetCallbackResult() 
     { 
      return "";//throw new NotImplementedException(); 
     } 

     public void RaiseCallbackEvent(string eventArgument) 
     { 
      NumericUpDownChangedArgs nudca = new NumericUpDownChangedArgs(long.Parse(eventArgument)); 
      OnNumericUpDownEvent(this, nudca); 
     } 

     #endregion 
    } 

    /// <summary> 
    /// Class that adds the prestamoList to the event 
    /// </summary> 
    public class NumericUpDownChangedArgs : System.EventArgs 
    { 
     /// <summary> 
     /// The current selected value. 
     /// </summary> 
     public long Value { get; private set; } 

     public NumericUpDownChangedArgs(long value) 
     { 
      Value = value; 
     } 
    } 

} 


using System; 
using System.Collections.Generic; 
using System.Text; 

namespace Corp 
{ 
    /// <summary> 
    /// Summary description for CorpAjaxControlToolkitUserControl 
    /// </summary> 
    public class CorpNumericUpDown : CorpAjaxControlToolkitUserControl 
    { 
     private Int16 _currentInstanceNumber; // This variable hold the instanceNumber assignated at first place. 

     public short currentInstanceNumber 
     { 
      get { return _currentInstanceNumber; } 
      set { _currentInstanceNumber = value; } 
     } 

     protected void Page_PreRender(object sender, EventArgs e) 
     { 
      const string strOnChange = "OnChange"; 
      const string strCallServer = "NumericUpDownCallServer"; 

      StringBuilder str = new StringBuilder(); 
      foreach (KeyValuePair<String, Int16> control in controlsToRegister) 
      { 
       str.Append("function ").Append(strOnChange + control.Value).Append("(sender, eventArgs) ").AppendLine(); 
       str.Append("{").AppendLine(); 
       str.Append(" if (sender) {").AppendLine(); 
       str.Append("  var hfield = document.getElementById('").Append(control.Key).Append("');").AppendLine(); 
       str.Append("  if (hfield.value != eventArgs) {").AppendLine(); 
       str.Append("   hfield.value = eventArgs;").AppendLine(); 
       str.Append("   ").Append(strCallServer + control.Value).Append("(eventArgs, eventArgs);").AppendLine(); 
       str.Append("  }").AppendLine(); 
       str.Append(" }").AppendLine(); 
       str.Append("}").AppendLine(); 
       Page.ClientScript.RegisterClientScriptBlock(typeof(CorpNumericUpDown), Guid.NewGuid().ToString(), str.ToString(), true); 
      } 

      str = new StringBuilder(); 
      foreach (KeyValuePair<String, Int16> control in controlsToRegister) 
      { 
       str.Append(" funcsPageLoad[funcsPageLoad.length] = function() { $find('NumericUpDownEx" + control.Value + "').add_currentChanged(").Append(strOnChange + control.Value).Append(");};").AppendLine(); 
       str.Append(" funcsPageUnLoad[funcsPageUnLoad.length] = function() { $find('NumericUpDownEx" + control.Value + "').remove_currentChanged(").Append(strOnChange + control.Value).Append(");};").AppendLine(); 
      } 
      Page.ClientScript.RegisterClientScriptBlock(typeof(CorpNumericUpDown), Guid.NewGuid().ToString(), str.ToString(), true); 
     } 
    } 
} 

내가 이것을 사용로드 뷰를 만들 :

은 사용자 컨트롤의 코드와 부모

beginRequest 이벤트는 비동기의 처리 전에 발생합니다 // 포스트 백이 시작되고 포스트 백이 서버로 전송됩니다. 이 이벤트를 사용하여 사용자 정의 스크립트를 호출하여 요청 헤더를 설정하거나 포스트 백이 처리되고 있음을 사용자에게 알리는 애니메이션을 시작할 수 있습니다. . Sys.WebForms.PageRequestManager.getInstance() add_beginRequest ( 함수 (송신자에 args) { VAR modalPopupBehavior = $ ('programmaticSavingLoadingModalPopupBehavior') 찾을; modalPopupBehavior.show();} )를;

// 비동기 포스트 백이 끝나고 컨트롤이 브라우저로 반환 된 후에 endRequest 이벤트가 발생합니다. 이 이벤트를 사용하여 사용자에게 알림을 제공하거나 오류를 기록 할 수 있습니다. . Sys.WebForms.PageRequestManager.getInstance() add_endRequest ( 함수 (발신자, ARG) { VAR modalPopupBehavior = $ ('programmaticSavingLoadingModalPopupBehavior') 찾을; modalPopupBehavior.hide();} )를;

미리 감사드립니다. 다니엘.

답변

2

나는 5 월 이후에 이것을 알아 냈다고 가정하고 있습니다. 문제를 해결하기위한 다른 경로를 취했으나 동일한 질문을 제기 할 수있는 다른 사용자에게 응답하려고합니다.

웹 폼 콜백 후 클라이언트 브라우저로 다시 보내지는 유일한 응답은 GetCallbackResult에 의해 반환되는 문자열입니다. 그런 다음 "ReceiveServerDataNumericUpDown"에서 Page.ClientScript.GetCallbackEventReference에 전달 된 clientCallback 매개 변수와 동일한 이름의 javascript 메서드를 만듭니다.

이 함수는 클라이언트 쪽에서 텍스트 상자의 값을 업데이트하는 작업을 수행 할 수 있습니다.

관련 문제