Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Ajax、回调、回发和Sys.WebForms.PageRequestManager.getInstance().add_beginRequest_C#_Asp.net_Ajax_Callback_Webforms - Fatal编程技术网

C# Ajax、回调、回发和Sys.WebForms.PageRequestManager.getInstance().add_beginRequest

C# Ajax、回调、回发和Sys.WebForms.PageRequestManager.getInstance().add_beginRequest,c#,asp.net,ajax,callback,webforms,C#,Asp.net,Ajax,Callback,Webforms,我有一个用户控件,它封装了NumericUpDownExtender。此UserControl实现接口ICallbackEventHandler,因为我希望在用户更改与服务器中引发的自定义事件相关联的文本框的值时实现该接口。另一方面,每次异步回发完成时,我都会显示一条加载和禁用整个屏幕的消息。当通过以下几行代码在例如UpdatePanel中更改某些内容时,这种方法非常有效: Sys.WebForms.PageRequestManager.getInstance().add_beginReques

我有一个用户控件,它封装了NumericUpDownExtender。此UserControl实现接口ICallbackEventHandler,因为我希望在用户更改与服务器中引发的自定义事件相关联的文本框的值时实现该接口。另一方面,每次异步回发完成时,我都会显示一条加载和禁用整个屏幕的消息。当通过以下几行代码在例如UpdatePanel中更改某些内容时,这种方法非常有效:

Sys.WebForms.PageRequestManager.getInstance().add_beginRequest( 函数(发送方,参数){ var modalPopupBehavior=$find('programmaticSavingLoadingModalPopupBehavior'); modalPopupBehavior.show(); } );

UserControl位于detailsview中,detailsview位于aspx中的UpdatePanel中。当引发自定义事件时,我希望aspx中的另一个文本框更改其值。到目前为止,当我单击UpDownExtender时,它会正确地进入服务器并引发自定义事件,文本框的新值会在服务器中分配。但它不会在浏览器中更改

我怀疑问题出在回调上,因为我的UserControl与AutoCompleteXtender具有相同的体系结构,AutoCompleteXtender实现了IPostbackEventHandler,并且可以正常工作。 有什么线索可以告诉我如何在这里解决此问题,使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);
        }
    }
}
使用系统;
使用System.Web.UI;
使用系统组件模型;
使用系统文本;
命名空间公司用户控件
{
[主题(正确)]
公共部分类CustomNumericUpDown:CorpNumericUpDown,ICallbackEventHandler
{
受保护的无效页面\u预呈现(对象发送方,事件参数e)
{
如果(!Page.IsPostBack)
{
currentInstanceNumber=CorpAjaxControlToolkitUserControl.getNextInstanceNumber();
}
寄存器控制(this.HFNumericUpDown.ClientID,currentInstanceNumber);
字符串strCallServer=“NumericUpDownCallServer”+currentInstanceNumber.ToString();
//如果未编写此函数,则获取DisposibilidCliente的回调将不起作用
如果(!Page.ClientScript.IsClientScriptBlockRegistered(“ReceiveServerDataNumericUpDown”))
{
StringBuilder str=新的StringBuilder();
Append(“函数ReceiveServerDataNumericUpDown(arg,context){}”).AppendLine();
Page.ClientScript.RegisterClientScriptBlock(typeof(CorpNumericUpDown),
“ReceiveServerDataNumericUpDown”,str.ToString(),true);
}
nudeNumericUpDownExtender.BehaviorID=“NumericUpDownEx”+currentInstanceNumber.ToString();
ClientScriptManager cm=Page.ClientScript;
字符串cbReference=cm.GetCallbackEventReference(这是“arg”、“ReceiveServerDataNumericUpDown”、“arg”);
字符串callbackScript=“function”+strCallServer+“(arg,context)”+Environment.NewLine+“{”+Environment.NewLine+cbReference+”;“+Environment.NewLine+”}”+Environment.NewLine;
cm.RegisterClientScriptBlock(typeof(CustomNumericUpDown),strCallServer,callbackScript,true);
基本。页面预呈现(发送方,e);
}
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Bindable(true)]
公共Int64值
{
获取{return(string.IsNullOrEmpty(HFNumericUpDown.Value)→Int64.Parse(“1”):Int64.Parse(HFNumericUpDown.Value));}
设置
{
HFNumericUpDown.Value=Value.ToString();
//txtAutoCompleteClienter\u autoCompleteTeeXtender.ContextKey=value.ToString();
//TODO:更改文本框的文本
}
}
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Bindable(true)]
[说明(“数字向上向下的文本”)]
公共字符串文本
{
获取{return txtNumericUpDown.Text;}
设置{txtNumericUpDown.Text=value;}
}
公共委托无效NumericUpDownChangedHandler(对象发送方,NumericUpDownChangedArgs e);
公共事件NumericUpDownChangedHandler numericUpDownEvent;
[System.ComponentModel.Browsable(true)]
[System.ComponentModel.Bindable(true)]
[System.ComponentModel.Description(“在数量增加或减少后引发”)]
NumericUpDownEvent上受保护的虚拟无效(对象发送方,NumericUpDownChangedArgs e)
{
if(numericUpDownEvent!=null)//检查是否有人附加到该事件
numericUpDownEvent(本,e);
}
#区域ICallbackEventHandler成员
公共字符串GetCallbackResult()
{
返回“”;//抛出新的NotImplementedException();
}
public void RaiseCallbackEvent(字符串事件参数)
{
NumericUpDownChangedArgs nudca=新的NumericUpDownChangedArgs(long.Parse(eventArgument));
OnNumericUpDownEvent(本,nudca);
}
#端区
}
/// 
///类,该类将prestamoList添加到事件中
/// 
公共类NumericUpDownChangedArgs:System.EventArgs
{
/// 
///当前选定的值。
/// 
公共长值{get;private set;}
公共数字上下变化量(长值)
{
价值=价值;
}
}
}
使用制度;
使用System.Collections.Generic;
使用系统文本;
命名空间公司
{
/// 
///CorpAjaxControlToolkitUserControl的摘要说明
/// 
公共类CorpNumericUpDown:CorpAjaxControlToolkitUserControl
{
private Int16\u currentInstanceNumber;//此变量保存instanceNumber a