none
如何传一个函数给用户控件? RRS feed

  • 问题

  • 我想传一个函数给一个用户控件,这个函数在用户控件中多次用到,但我用下面的代码得到了错误,请问如果做?谢谢!


    Error 1 Inconsistent accessibility: property type 'UserControl_RunCode.delegateGetDynamicDimFromControl' is less accessible than property 'UserControl_RunCode.GetDynamicDimFromControl'
    E:\ASP.NET4.0_Calculator\hicalc\UserControl\RunCode.ascx.cs 22 45 E:\ASP.NET4.0_Calculator\hicalc\


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class UserControl_RunCode : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public int InputedID //It's OK
        {
            get { return Convert.ToInt32(ViewState["InputedID"].ToString()); }
            set { ViewState["InputedID"] = value.ToString(); }
        }

        delegate dynamic[] delegateGetDynamicDimFromControl(Panel PanelInput);

        public delegateGetDynamicDimFromControl GetDynamicDimFromControl //It's wrong
        {
            get {
                  return (delegateGetDynamicDimFromControl)ViewState["GetDynamicDimFromControl"];
                }
            set {
                 ViewState["GetDynamicDimFromControl"] = value;
                }
        }

    }

    2010年7月21日 3:23

答案

全部回复

  • 我想传一个函数给一个用户控件,这个函数在用户控件中多次用到,但我用下面的代码得到了错误,请问如果做?谢谢!


    Error 1 Inconsistent accessibility: property type 'UserControl_RunCode.delegateGetDynamicDimFromControl' is less accessible than property 'UserControl_RunCode.GetDynamicDimFromControl'
    E:\ASP.NET4.0_Calculator\hicalc\UserControl\RunCode.ascx.cs 22 45 E:\ASP.NET4.0_Calculator\hicalc\

     


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class UserControl_RunCode : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        public int InputedID //It's OK
        {
            get { return Convert.ToInt32(ViewState["InputedID"].ToString()); }
            set { ViewState["InputedID"] = value.ToString(); }
        }

        delegate dynamic[] delegateGetDynamicDimFromControl(Panel PanelInput);

        public delegateGetDynamicDimFromControl GetDynamicDimFromControl //It's wrong
        {
            get {
                  return (delegateGetDynamicDimFromControl)ViewState["GetDynamicDimFromControl"];
                }
            set {
                 ViewState["GetDynamicDimFromControl"] = value;
                }
        }

    }

    2010年7月21日 3:20
  • 因為您在 public 的member 中使用了 僅具有 internal 存取權的 method.....

    試著把 delegateGetDynamicDimFromControl 的存取修飾詞改為 public 看看~


    小中中的學習筆記
    2010年7月21日 6:17