kobe
kobe

Reputation: 15835

Accessing Page properties from Base User Control which gets extened by all user controls

I have a Page with few web user controls in it

Page does the following , it extends Icode interface

 public partial class TestPage: System.Web.UI.Page, ICode

// it implements Code implementation here

public string Code
        {
            get
            {
                return "sample code";
            }
        }

One of the control is as below

I am able to access the Code value from this sample control

sampleControl:BaseControl

// here I am able to access the page property's

            if (Page is ICode)
            {
                string test= ((ICode))Page).Code;
            }

Now i want to access the same value from BaseControl, as baseControl is getting executed before the page i am unable to set the values in the base control.

BaseControl: System.Web.UI.UserControl
{
   // how can i access those values here.
}

if i can set the values in the base control, all controls can acess that value

any help will be appreciated

Upvotes: 1

Views: 985

Answers (1)

Joel C
Joel C

Reputation: 5567

It sounds like you have your dependency chain reversed. A control is supposed to be a reusable unit, and a page should contain controls. You shouldn't be trying to access page-level properties from within your control, you should be setting the control's properties from your page.

Upvotes: 2

Related Questions