ASP.NET Access Page variables from User Control

BasePage class

namespace Classes{    public class BasePage : System.Web.UI.Page    {        public string CurrentBusinessPartnerID = "testId";    }}

BaseUserControl class

namespace Classes{    public class BaseUserControl : System.Web.UI.UserControl    {        private string _currentBusinessPartnerID = null;        public BaseUserControl()        {                   }        public string CurrentBusinessPartnerID        {            get            {                BasePage currentPage = (BasePage) this.Page;                                if (currentPage != null)                {                    currentPage = (BasePage)HttpContext.Current.Handler;                }                _currentBusinessPartnerID = currentPage.CurrentBusinessPartnerID;                return _currentBusinessPartnerID;            }        }    }}

User Control

// insteadpublic partial class UtilityMenu : System.Web.UI.UserControl// use thispublic partial class UtilityMenu : Classes.BaseUserControl{    protected void Page_Load(object sender, EventArgs e)    {        litTest.Text = CurrentMeter.StreetAddress;    }}

Leave a Reply

Your email address will not be published. Required fields are marked *