代码之家  ›  专栏  ›  技术社区  ›  djdd87

为什么我的属性在Ajax控件中不公开?

  •  0
  • djdd87  · 技术社区  · 15 年前

    我试图创建一个Ajax控件,但我看不到该属性get_u和set_u方法。

    这是我在.js文件中得到的代码:

    Type.registerNamespace('MyCompany.ControlLibrary');
    
    MyCompany.ControlLibrary.WebNotify = function(element)
    {
        // Module level variables
        this._message = '';
    
        //Calling the base class constructor
        MyCompany.ControlLibrary.WebNotify.initializeBase(this, [element]);
    }
    
    
    MyCompany.ControlLibrary.WebNotify.prototype =
    {
        //Getter for Message Property
        get_message : function()
        {
            return this._message;
        },
    
        //Setter for Message Property
        set_message : function(value)
        {debugger;
            var e = Function._validateParams(arguments, [{name: 'value', type: String}]);
            if (e) throw e;
    
            if (this._message != value)
            {
                // Only sets the value if it differs from the current
                this._message = value;
                //Raise the propertyChanged event
                this.raisePropertyChanged('message'); //This is a base class method which resides in Sys.Component
            }
        },
    
        initialize : function()
        {
            //Call the base class method
            MyCompany.ControlLibrary.WebNotify.callBaseMethod(this, 'initialize');
        },
    
        dispose : function()
        {
            //Call the base class method
            MyCompany.ControlLibrary.WebNotify.callBaseMethod(this, 'dispose');
        }
    }
    
    
    
    
    
    MyCompany.ControlLibrary.WebNotify.registerClass('MyCompany.ControlLibrary.WebNotify', Sys.UI.Control);
    
    if (typeof(Sys) != 'undefined')
    {
        Sys.Application.notifyScriptLoaded();
    }
    

    这是我在code behind.cs文件中的属性:

    [DescriptionAttribute("The message that is displayed in the notifier.")]
    public string Message
    {
        get { return _message; }
        set { _message = value; }
    }
    private string _message = "No Message Specified";
    

    编辑:这是我的全部代码:

    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.ComponentModel;
    using System.Web.Services;
    using System.Collections.Generic;
    
    namespace MyCompany
    {
        [DefaultProperty("ID")]
        [ToolboxData("<{0}:WebNotify runat=server />")]
        public class WebNotify : Button, IScriptControl
        {
    
    
    #region Constructors
    
            public WebNotify()
            {
    
            }
    
    #endregion
    
    
    #region Page Events
    
    
            protected override void OnLoad(EventArgs e)
            {
                base.OnLoad(e);
            }
    
            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
            }
    
            protected override void OnPreRender(EventArgs e)
            {
    
                if (!this.DesignMode)
                {
                    ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
                    if (scriptManager != null)
                    {
                        scriptManager.RegisterScriptControl(this);
                    }
                    else
                        throw new ApplicationException("You must have a ScriptManager on the Page.");
                }
    
                base.OnPreRender(e);
    
            }
    
            protected override void Render(HtmlTextWriter writer)
            {
                if (!this.DesignMode)
                {
                    ScriptManager.GetCurrent(this.Page).RegisterScriptDescriptors(this);
                }
                base.Render(writer);
            }
    
            protected override void CreateChildControls()
            {
    
                base.CreateChildControls();
    
            }
    
    
    
    #endregion
    
    
    #region Properties
    
    
            [DescriptionAttribute("The message that is displayed in the notifier.")]
            public string Message
            {
                get { return _message; }
                set { _message = value; }
            }
            private string _message = "No Message Specified";
    
    
    
    #endregion
    
    
    
    #region IScriptControl
    
    
            IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
            {
                ScriptControlDescriptor desc = new ScriptControlDescriptor("MyCompany.WebNotify", ClientID);
                desc.AddProperty("message", this.Message);
                yield return desc;
            }
    
            IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
            {
                yield return new ScriptReference(Page.ResolveUrl("~/WebNotify.js"));
            }
    
    
    #endregion
    
    
        }
    }
    
    2 回复  |  直到 15 年前
        1
  •  0
  •   Dewfy    15 年前

    代码隐藏未命中[ExtenderControlProperty]属性

        2
  •  0
  •   djdd87    15 年前

    我不需要任何Ajax控制工具包。我只需要使用$find而不是$get。现在我用美元,一切都很好。

    多头疼啊。