为什么我的属性得到并设置为不在AJAX控件中公开?

时间:2009-08-17 09:42:50

标签: c# asp.net javascript ajax

我正在尝试创建一个AJAX控件,我无法在控件中看到属性get_和set_方法。

这是我在.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();
}

这是我在.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 个答案:

答案 0 :(得分:0)

miss miss [ExtenderControlProperty]属性

后面的代码

答案 1 :(得分:0)

我不需要任何AJAX Control Kit的东西。我只需要使用$ find而不是$ get。现在我使用$发现一切都很完美。

真是头疼。