简体   繁体   中英

How to call Parent Page property in UserControl

I have my parent page as OPC.aspx where Addressdetail.ascx is declared as usercontrol.

Now I have made one property in my parent page(OPC.aspx) as

public string SelectedOptionUserControl { get; set; } 

Now I want to set property named SelectedOptionUserControl in usercontrol(Addressdetail.ascx) ie I want to set the property of parent page in child page

on Addressdetail.ascx code below

protected void Page_Load(object sender, EventArgs e)
    {
     this.Page.Master.SelectedOptionUserControl="abc";
     this.Page.GetType().InvokeMember("SelectedOptionUserControl", System.Reflection.BindingFlags.InvokeMethod, null, this.Page, new object[] { "abc" });
    }

I have tried this 2 ways but not working for me.

This

public string SelectedOptionUserControl { get; set; } 

declares a property, not a method.

So change

System.Reflection.BindingFlags.InvokeMethod

To

System.Reflection.BindingFlags.SetProperty

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM