I have a Class With one Property and around 6 Public Methods (nothing is static/shared).
My aspx pages set’s the Class property to some value, as soon as value is set I can Access Class Methods within the aspxPage, now thats fine. I have 3 web user controls within my aspx page, I need to access few of the Class methods within these web user controls, I dont really want to create the new instance of class within each of those user controls.
For Example url has the Category Code 25, when 25 passed to Class, Class have different methods to create Breadcrumb, SEO friendly URL’s etc….and different user controls with page are performing different tasks, for Example Class.CreateMenu, Class.PageTitle etc.
So what would be the best way where I can institate the class within my aspx page ONCE and have my web user controls access its members.
You’ve to instantiate the class in
Page_InitorPage_Loadmethod and save it toSessionorViewStateso this reference can be available touser controls.and read
boundedobject,Alternatively add public property/method to each user control.
and assign object reference from within the page event handler (Page_Load)